obsidiansystems / dependent-map

Dependently-typed finite maps (partial dependent products)
Other
63 stars 33 forks source link

Consider changing the Monoid instance #12

Open treeowl opened 8 years ago

treeowl commented 8 years ago

Pretty much everyone hates the Monoid instance for Data.Map. If you're not too terribly opposed to potentially breaking existing code to make future users happy, you can avoid the problem here.

class Semigroup1 f where
  (<<>>) :: f a -> f a -> f a

instance (GCompare k, Semigroup1 f) => Monoid (DMap k f) where
  mappend = unionWith (<<>>)
endgame commented 3 weeks ago

The Monoid instance for most maps is a massive footgun and should be replaced with a unionWith-based one. But I don't know if we want to introduce a new typeclass. I also am not sure that Alt (from semigroupoids) or Alternative are right, either: although they describe a Semigroup or Monoid on applicative functors, they usually often have an interpretation that might not be appropriate (there's usually a notion of "choiceyness" in those instances, although [] or Maybe will do what you expect).

What if you used a quantified constraint like instance (GCompare k, forall a . Semigroup (f a)) => Monoid (DMap k f)?