<A HREF="manual_contents.html"><img align=center src="contents.gif" ALT="Contents"></A> Up Previous Next

Print type of expression :type <expr>


The :type command can be used to print the type of an expression without evaluating it. For example:

 Prelude> :t "hello, world"

 "hello, world" :: String

 Prelude> :t putStr "hello, world"

 putStr "hello, world" :: IO ()

 Prelude> :t sum [1..10]

 sum (enumFromTo 1 10) :: (Num a, Enum a) => a

 Prelude>

Note that Hugs displays the most general type that can be inferred for each expression. For example, compare the type inferred for sum [1..10] above with the type printed by the evaluator (using :set +t):

 Prelude> :set +t

 Prelude> sum [1..10]

 55 :: Int

 Prelude>

The difference is explained by the fact that the evaluator uses the Haskell default mechanism to instantiate the type variable a in the most general type to the type Int, avoiding an error with unresolved overloading.