Conversation

TIL, #Haskell classes are _collection of_ types. They themselves are not types. It's a bit different from OO world, where classes _are_ types. In that sense, Functor is a collection of classes, it allows me to map from type `a` to type `b` in a particular class. 🤔 #TypeClasses
5
5
Seeing classes as a subset of types (equivalently, a constraint on what types are allowed) is great! I think looking at Functor as a collection of classes is wrong, though. Instead, it's a collection of (or constraint on) type *constructors*.
1
2
> classes as a subset of types Yeah, that's another way to look at it, and really good one. Thanks Chris! > Functor is a collection of classes Well, if a class (* -> *) is collection of types, then Functor ((* -> *) -> *) feels more like collection of classes.
2
(* -> *) isn't a class, though. That's a type constructor (or a type family, etc.). If you want to think of a type class as mapping a type to something, then it maps types to *values*. This is something you can't really express in Haskell directly.
1
1
I see.. I mix up `class` and `data` construct of Haskell, I guess. Can you point to thing in which I can express it (Idris 🤔) or related material?
1
Great question! Idris lets types depend on values, but values that depend on types are just plain polymorphism, and actually many languages do that! To define an arbitrary map from types to values is "ad hoc polymorphism". Haskell can actually do that... using type classes.
2
1
Oh yes, that's polymorphism. I can't help but wonder whether we have a concept of first-class polymorphism? Hmm.. I think, almost all the languages have special construct for polymorphism, e.g. Haskell's `class`.. Would it be beneficial to have them as first-class entity? 🤔
2
according your code snippet, I think type class (ad hoc polymorphism) going to be first-class in Pikelet, correct? being a function type? Maybe I'm again mixing it up! 😬What do you think about first-class polymorphism?
1
Show replies