[Haskell-beginners] numerical types, the $ operator

TG cowscanfly at airpost.net
Sat Mar 28 17:18:46 EDT 2009

Hi all
I'm trying to understand the following simple function

>-- | fractional part of number.
>frac :: (RealFrac a) => a -> a
>frac x = x - fromInteger . floor $ x

which apparently is wrong. Whereas this is ok

>frac x = x - fromInteger (floor x)

Is the 1st one wrong because it is trying to apply the _whole_ 'left of
$' to the 'x' on the right?
How would an experienced guy write this without parentheses?

Moreover, I've put the 'RealFrac' by looking at ":t floor".
What kind of class constraint whould you put for doing eg:

>frac x = x - fromInteger (floor (sqrt x) )

since 'floor' takes fractional and 'sqrt' takes RealFrac? Some kind of
Thank you.

Seems that types are half the language, if not more ..

  cowscanfly at airpost.net

http://www.fastmail.fm - Access your email from home and the web

More information about the Beginners mailing list