[Haskell-beginners] Retrieving the decimal portion of a Double

Dominic Sim dskw_86 at yahoo.com
Mon Nov 23 09:31:05 EST 2009


    Hi all,

    I am trying to retrieve the decimal portion of a Double. My code is:

    getDecimal x = x - floor(x)

    I would expect the following:

    Main> getDecimal 1.23
    0.23 :: [Double]

    but instead, I get:

    Main> getDecimal 1.23
    ERROR - Unresolved overloading
    *** Type       : (RealFrac a, Integral a) => a
    *** Expression : getDecimal 1.23

    I have tried adding "getDecimal :: Double -> Double" but it only causes the following message to appear:

    ERROR file:C:\Documents and Settings\User\file.hs:60 - Instance of Integral Double required for definition of getDecimal

    How should I define my function so that it'll work? Thanks!

    Regards,
    Dom



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20091123/1ce2a1dc/attachment.html


More information about the Beginners mailing list