I'm learning about paradigms of functional languages. So I've read that while Subtype polymorphism is typical for OO languages, Parametric polymorphism is typical for functional languages.
But I wonder if there is Subtype polymorphism in functional languages. The functional language I know best is Haskell, and I know there are typeclasses in Haskell.
I always thought of typeclasses to be somewhat similiar to interfaces, and interfaces are Subtype polymorphism. E.g. here:
data Foo a = Bar a | Baz String
deriving instance Eq a => Eq (Foo a)
Eq is a typeclass that defines the (==) operator. That's basically like a Foo class implementing a Eq interface.
So what I'm asking is: Is this considered Subtyping (or Subtype polymorphism)?
mapfunction. With typeclasses, it can act on several different collection types and return the original collection type. With OO interfaces, it's not possible to do this in a type-safe way. Try to implement this in Java or C# and you'll see.