[Haskell-beginners] typeOf raises Error

Brent Yorgey byorgey at seas.upenn.edu
Sun Jan 11 11:22:28 EST 2009


As Brandon explained, since 1 is polymorphic, and print is polymorphic
in its argument, the compiler doesn't know which type to choose.  You
could fix it, for example, like this:

> ------------
> import Data.Typeable
> 
> main=
>  print (typeOf (1 :: Integer))
> ------------

You might protest, what is the point of using typeOf if you have to
actually put in the type annotation anyway?  Well, this is a rather
contrived example; usually in a real program GHC would be able to
infer the type and an annotation would be unnecessary.

-Brent


More information about the Beginners mailing list