3 ms·
A typeclass should indicate some semantic relationship between its instances, so IMO they do provide a safe version of ad-hoc polymorphism. You shouldn't have t
by lmm 11y ago
A typeclass should indicate some semantic relationship between its instances, so IMO they do provide a safe version of ad-hoc polymorphism. You shouldn't have to name the (type, operation) pair; the whole point of typeclass coherence is that specifying the type and the operation is enough.
I do think typeclass programming could do with having the same functionality as ordinary programming available. Here in Scala typeclasses are ordinary values (resolved via an implicit mechanism), which enables a lot - though the cost of abandoning global coherence is high.
Ultimately, syntax and conciseness does matter. I don't think anything as verbose as that link has a chance of getting off the ground.
- whateveracct 11y agoI wouldn't call the "cost of abandoning global coherence" to be "high." Outside of data structures that depend on typeclass instances (like Set), it doesn't especially harm my ability to reason about my or others' code in my experience. And the data structures issue (what happens when I join two Sets with potentially different Order instances) can be solved with Scala's dependent type features I believe.
- lmm 11y ago> And the data structures issue (what happens when I join two Sets with potentially different Order instances) can be solved with Scala's dependent type features I believe. Not really. There's no way to enforce that each Order has a singleton type which is what you'd need to resolve that.