instance Applicative Data.Map

Henning Thielemann lemming at henning-thielemann.de
Wed Nov 14 21:28:06 CET 2012


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.



More information about the Libraries mailing list