[Haskell-cafe] Re: Begginer question

Jules Bean jules at jellybean.co.uk
Thu Jan 6 09:12:39 EST 2005


On 6 Jan 2005, at 14:06, Maurício wrote:
> *****
> import Complex;
> a = 3 :+ 4;
> *****
>
> and load it into ghci, "a + 4" gives me "7.0 :+ 4.0", although "a + 
> (4::Float)" gives me that error again. Why Haskell converts "4" to 
> Complex but not a Float?
>

The answer lies available to you in ghci:

Prelude> :t 4
4 :: forall t. (Num t) => t

The type of for is 'any type in the Num class'.  So '4' stands for the 
Integer four as well as the Float four and the Double four and indeed 
the Complex 4.

No conversion is actually happening.

Jules



More information about the Haskell-Cafe mailing list