[Haskell-cafe] Printing the empty list.

Henning Thielemann schlepptop at henning-thielemann.de
Sat Jul 2 19:08:16 CEST 2011


On 01.07.2011 00:58, Joshua Ball wrote:
> GHCi seems to be clever about some things:
>
> If I try to print the empty list in ghci, I encounter no problems:
>
> Prelude>  []
> []
> Prelude>  show []
> "[]"
> Prelude>  print []
> []
>
> Even though the type of the list is clearly unknown, it must be
> picking SOME type. (why does it print [] instead of "")?
>
> If I write a program in a file and load it in
>
> main = print []
>
> Then I get the ambiguous type variable error that I would expect. Why
> doesn't ghci generate this error at the prompt?

GHCi will warn you, that type defaulting was used, if you start it with

ghci -Wall




More information about the Haskell-Cafe mailing list