[Haskell-cafe] What does the Haskell type system do with "show (1+2)"?

Henning Thielemann lemming at henning-thielemann.de
Fri Jan 13 05:31:50 EST 2006


On Thu, 12 Jan 2006 Jeff.Harper at handheld.com wrote:

> What does the Haskell type system do with expressions such as these . . .
> ?
>   show 1
>   show (1+2)
>
> The type of the subexpressions "1" and "1+2" are "ambiguous" since they
> have type "(Num a) => a".  I'm under the assumption before "1+2" is
> evaluated, the "1" and "2" must be coerced into a "concrete" type such as
> Int, Integer, Double, etc, and before "show 1" is evaluated, the "1" must
> be coerced into a "concrete" type.  Is my assumption correct?

Yep. If you start ghc with -Wall option then it also tells you that some 
automatism is invoked.


More information about the Haskell-Cafe mailing list