[Haskell-cafe] Types

Miguel Mitrofanov miguelimo38 at yandex.ru
Fri Nov 27 00:44:56 EST 2009

>> I know that 2 is something of the type Integral, however what does  
>> this
>> differ from Int? The same question goes for Fractional and  
>> Floating, what
>> exactly is their commonality and what exactly is their difference?
> Numeric literals are a special case.  To make it possible to write  
> "2" and
> mean it as an Int or an Integer (or any other numeric type), 2 is  
> defined
> to *really* mean (fromIntegral 2).  fromIntegral is a function that  
> takes an
> Integral value (such as 2), and converts it to a type of your  
> choice, so
> long as it's a member of the Num class.

Ahem. 2 is defined to really mean (fromInteger 2), not "fromIntegral".  
And "fromInteger" takes an *Integer* value.

More information about the Haskell-Cafe mailing list