3 ms·
So you would not use type-classes in Haskell as they rely on implicitly passed parameters to functions?
by still_grokking 6y ago
So you would not use type-classes in Haskell as they rely on implicitly passed parameters to functions?
- kqr 6y agoI can't speak for the GP, but what makes typeclasses in Haskell work for me is that there's a very strong cultural force ensuring that they are truly about consistency boundaries and maintaining invariants/laws. Haskell developers don't just create a typeclass to bunch related functionality together. Doing so is a common beginner's anti-pattern. Typeclasses exist to wrap up general operations that satisfy some laws. When objects in OOP are used in the same way, I don't mind it as much. It's when they're not that I don't find the syntactic inconvenience worth it.
- js8 6y agoIn Haskell typeclasses, it's the type of the parameter that is implicitly passed, not the parameter itself.
- uryga 6y agoi don't think that's correct, afaik typeclasses roughly desugar to passing a record of functions (vtable/"dictionary") at the call site
- taejo 6y agoAnd that vtable depends on the type, not the value.
- uryga 6y agoi guess there's really two implicit arguments - the value's type, `a` (quantified via forall - the System F "Λ") and its vtable `Show a`... though i guess the vtable is uniquely determined by the type bc in Haskell instances are globally unique