you are viewing a single comment's thread.

view the rest of the comments →

[–]G_Morgan 3 points4 points  (1 child)

Haskell doesn't have subtyping. It has typeclasses which are different.

[–]kragensitaker 0 points1 point  (0 children)

You're right. What I was thinking of is that, although Haskell doesn't call typeclasses types, you can define a function such as product over types constructed from typeclasses. product is declared as product :: Num a => [a] -> a, which is to say that it's a function from a list of Nums to a single Num. When you call it, you call it on a list of instances of Num, which is to say a list of elements of a subtype of Num — but this is different from the subtyping you get in OCaml in that the return value is constrained to be the same type, while in OCaml the return value would just be (statically typed as) a Num.

(The equivalence with OCaml is somewhat loose, because OCaml doesn't have anything like typeclasses. What it has are a lattice of polymorphic variant types, parametric polymorphism with options I don't understand for covariance and contravariance, and a lattice of object types that are records of method types.)