Hacker News new | ask | show | jobs
by marcosdumay 531 days ago
> Haskell developers incorrectly assume that you can only have one semi group (or equality, monoid, etc) instances for your data type

They don't assume that. The devs bent the compiler backwards several times trying to support more than one instance, but they still couldn't design an implementation that is actually good to use.

If you know of any language where this works well, it would be nice to know. AFAIK, representing that kind of thing is an open problem, nobody has an answer.

3 comments

Scala does it well. Implicits make it easy to pass along the instance you mean. You can put a default on the companion object if you want, but you can override where needed. Implicits on the companion object have lower priority than those in current scope.
I think Idris addresses this fairly well, if there's more than one instance (and the code is ambiguous) you have to annotate which one.
Scala/Typescript