purescript-deprecated/purescript-maps

Add `Alt` and `Plus` instances

Opened this issue · 3 comments

Both Map k and StrMap should be instances of Alt and Plus, with union and empty as the corresponding methods.

Also, something odd I've noticed: While Map k a has a Semigroup instance as long as Ord k, StrMap a seems to require a Semigroup a instance... which means if I have a type Foo with no Semigroup instance, I have a Monoid instance for Map String Foo but not StrMap Foo, which is... odd, to say the least.

paf31 commented

👍

The Semigroup and Monoid instances for StrMap definitely look inconsistent with the ones for Map. Maybe they are the ones induced by the Applicative instance, but we should try to be consistent.

There's no Applicative instance either; not that this is a problem since Alt and Plus only require Functor. (There couldn't be an Applicative instance either, since there's no way to write pure :: v -> Map k v. I might be able to imagine an Apply instance given by zipping two maps together by the keys they have in common, but I'd have to think about it to make sure it's law-abiding.)

paf31 commented

I meant the Apply instance, for which there is definitely a law-abiding instance.