Conversation

When asked "When is a typeclass good", the common answer seems to be "When it has laws!" This is a good start, but I think this is only the start of the story. The answer /ought/ to be "When it has laws, and a unique (lawful) instance". (1/4)
7
53
This means most algebraic structures /do not/ make good typeclasses! For instance, consider Monoid. The thing that makes them cool is that there are a whole host of them! (2/4)
1
12
However, this is what makes programming with them /as a typeclass/ a huge pain. We need to constantly juggle newtypes just to convince instance selection to choose the right one, which is extremely clumsy. (3/4)
2
20
Do you mean, as a result of an instance being overridden at some higher level, then propagating down into library code where you really want the default?
1
Another approach would be: record SortedMap k v where constructor M ord : Ord k ... empty : Ord k => SortedMap k v empty @{ord} = M empty ord -- not sure if it's possible to bind instances like this
1
2
Show replies