[Haskell-cafe] Re: Begginer question

karczma at info.unicaen.fr karczma at info.unicaen.fr
Thu Jan 6 09:05:42 EST 2005

Maurício comments the remark of Ketil Malde 

>> Note that Haskell doesn't automatically convert arguments for you --
>> this is a feature.  

>   When I type this: 
> *****
> 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?

You should read thoroughly the Haskell documentation. You will learn
that Haskell casts EXPLICIT NUMERICAL CONSTANTS, but not variables. 

Actually this is not a "conversion", but an overloading of numerical
constants. The lexical entity "4" behaves as "fromInteger 4", and the
type checker uses the fromInteger appropriate to the context. Floating,
Complex, etc. With 4.0 it will work also (overloaded fromRational). 

Jerzy Karczmarczuk 

More information about the Haskell-Cafe mailing list