instance Applicative Data.Map
Brent Yorgey
byorgey at seas.upenn.edu
Thu Nov 15 00:35:44 CET 2012
On Wed, Nov 14, 2012 at 10:31:06PM +0200, Roman Cheplyaka wrote:
> * Henning Thielemann <lemming at henning-thielemann.de> [2012-11-14 21:28:06+0100]
> >
> > On Wed, 14 Nov 2012, Roman Cheplyaka wrote:
> >
> > >* Henning Thielemann <lemming at henning-thielemann.de> [2012-11-14 20:46:29+0100]
> > >>An ZipList-like Applicative instance for Data.Map would be nice. I
> > >>have an application where I like to write
> > >> liftA3 f amap bmap cmap
> > >> meaning
> > >> Map.intersectionWith ($) (Map.intersectionWith f amap bmap) cmap
> > >>
> > >>But I cannot complete the instance implementation because there is no
> > >>sensible definition for 'pure' for Data.Map. :-(
> > >
> > >You can lift Map like this:
> > >
> > > data ZipMap k a
> > > = Pure a -- a "Map" that maps every possible key to 'a'
> > > | Zip (Map k a)
> >
> > Yes, that would work. It is only annoying that for liftA3 I do not
> > need 'pure', at all. Thus we may note in the record that Data.Map is
> > an example where <*> and liftAn make sense (for n>0) but 'pure' (i.e.
> > Pointed) cannot be defined.
>
> True. It's like being a semigroup but not a monoid.
Precisely. See edwardk's package
http://hackage.haskell.org/package/semigroupoids
which defines this and many other related things.
-Brent
More information about the Libraries
mailing list