purescript-deprecated/purescript-maps

Meaning of semigroup for StrMap

Closed this issue · 4 comments

For Data.Map we have semigroup append as union, while for StrMap it appears to be the union of keys where matching entries have the reverse append of the value:

m1: fromList ((Tuple "d" "zz") : (Tuple "a" "a") : (Tuple "b" "b") : Nil)
m2: fromList ((Tuple "c" "z") : (Tuple "a" "x") : (Tuple "b" "y") : Nil)
m1 <> m2: fromList ((Tuple "c" "z") : (Tuple "a" "xa") : (Tuple "b" "yb") : (Tuple "d" "zz") : Nil)
paf31 commented

Well whatever we pick, the StrMap instance obviously has a bug. I think the two useful instances are union and unionWith (<>).

Does anyone have an argument for one of these options over the other? Personally, absent arguments to the contrary, I'd opt for matching the semantics of Data.Map.

I'm not aware of any argument for one over the other.

garyb commented

I don't have any good arguments for one over the other. I would find the current behaviour surprising if I'd tried it though. Anecdotally the union version would be my expectation... so if we're going to provide an instance that one would be my vote.