What does it mean that Haskell is weakly polymorphic? Does it have something to do with the fact that a Haskell function can not return a type?
Thanks!
What does it mean that Haskell is weakly polymorphic? Does it have something to do with the fact that a Haskell function can not return a type?
Thanks!
TL;DR: Haskell is not weakly polymorphic, but some tooling can behave like that under some circumstances if developer what it.
It seams OCaml have notion of
weakly polymorphic type variables
https://caml.inria.fr/pub/docs/manual-ocaml/polymorphism.html
Such a type variable is characterized by being able to only represent a single type and as soon as that type is inferred its every occurrence will be replaced by that type.
By that definition Haskell is NOT weakly polymorphic. Haskell will always infer broadest possible definition of a given type variable.
However, Haskell GHC compiler have what's called:
monomorphism restriction
Which forces behavior as described in OCaml weakly polymorphic variable. However, while OCaml behavior is toggle per variable. Haskell GHC behavior is controlled by runtime flag that is only active when doing interactive REPL, and even that can be turned off!