I\'m learning Haskell, and I was playing around in ghci when I came across something very puzzling.
First, create a simple add function:
Prelude>
It's the Monomorphism restriction. When you define a value with a simple pattern binding (just the name, without any function arguments) and without a type signature, it gets a monomorphic type. Any type variables are tried to be disambiguated according to the defaulting rules, if that doesn't succeed you get a type error.
In this case, the Num
constrained type variable gets defaulted to Integer
.
You can turn off the monomorphism restriction with
ghci> :set -XNoMonomorphismRestriction
or with the -XnoMonomorphismRestriction
flag on the command line.