[Haskell-cafe] coercion to Int

Lennart Augustsson lennart at augustsson.net
Fri Dec 31 13:34:07 EST 2004


fnK_ :: Int -> Int
fnK_ = round . sqrt . fromIntegral

james pentland wrote:
> what coercion can i use to get the below program to
> compile?
> 
> i see 
>     class  (Real a, Fractional a) => RealFrac a  where
>     round  :: (Integral b) => a -> b
> 
> and 
>     class  (Fractional a) => Floating a  where
>     sqrt      :: a -> a
> 
> various combinations of fromInteger, toInteger do not
> help.
> 
> 
> 
> 
> 
> fnK_ :: Int -> Int
> fnK_ x = round (sqrt x)         -- line 2
> 
> 
> 
> 
> 
> 
> Hugs session for:
> H:\Program Files\Hugs98\lib\Prelude.hs
> Prelude> :load xva
> Reading file "xva.hs":
> Type checking
> ERROR "xva.hs":2 - Instances of (RealFrac Int,
> Floating Int) required for definition of fnK_
> 
> 
> 
> 		
> __________________________________ 
> Do you Yahoo!? 
> Yahoo! Mail - Find what you need with new enhanced search.
> http://info.mail.yahoo.com/mail_250
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 



More information about the Haskell-Cafe mailing list