klequis / zz-haskell-notebook

Notes from learning Haskell
1 stars 0 forks source link

Monomorphism restriction #58

Open klequis opened 2 years ago

klequis commented 2 years ago

The monomorphism restriction is a counter-intuitive rule in Haskell type inference. If you forget to provide a type signature, sometimes this rule will fill the free type variables with specific types using "type defaulting" rules. The resulting type signature is always less polymorphic than you'd expect, so often this results in the compiler throwing type errors at you in situations where you expected it to infer a perfectly sane type for a polymorphic expression.