[Haskell-beginners] type error in sub-function

Brent Yorgey byorgey at seas.upenn.edu
Sat Feb 15 23:00:14 UTC 2014


On Sun, Feb 16, 2014 at 12:53:42AM +0200, Alexander Batischev wrote:
> But type defaulting doesn't kick in until the very last moment. Up until
> binding the result, it stays as polimorphic as possible:
> 
>     λ: :t 36
>     36 :: Num a => a
> 
> The moment you bind the result, though, it gets concrete type:
> 
>     λ: let x = 36
>     λ: :t x
>     x :: Integer

It has nothing to do with binding, actually.  The above is just due to
the monomorphism restriction.  If you turn it off (highly
recommended!):

   > :set -XNoMonomorphismRestriction
   > let x = 36
   > :t x
   Num a => a

-Brent


More information about the Beginners mailing list