[Haskell-beginners] subtle dissimilarity between fromInteger and fromIntegral

Joe Fredette jfredett at gmail.com
Wed Sep 30 19:57:00 EDT 2009


fromInteger takes an integer to any instance of the Num class. The num  
class provides this function, because (at least in theory) any Integer  
"is" (in some sense) an element of a Num instancing class.

fromIntegral has type `(Integral a, Num b) => a -> b` which means it  
takes any _integral) type (on that supports div and mod, and a  
function "toInteger" which takes an integral to an integer) to a num  
type. I imagine that "fromIntegral" is probably implemented

     fromIntegral = fromInteger . toInteger

HTH

/Joe

On Sep 30, 2009, at 7:41 PM, Hong Yang wrote:

> Hi,
>
> Can someone explain the subtle dissimilarity between fromInteger and  
> fromIntegral?
>
> Thanks,
>
> Hong
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners



More information about the Beginners mailing list