DEV Community

[Comment from a deleted post]
Collapse
 
sshine profile image
Simon Shine

This Semigroup instance breaks the semigroup laws, since

λ> mempty <> mojito
Cocktail {name = " Mojito", ingredients = ["rum","mint"]}

λ> mojito <> mempty
Cocktail {name = "Mojito ", ingredients = ["rum","mint"]}

If you want to fix this, consider making this a commutative monoid:

λ> (mojito <> robroy) == (robroy <> mojito)
...

...although I think sufficiently advanced drinks are not commutative because of chemistry.