[Haskell-cafe] CDouble type coercion

SevenThunders mattcbro at earthlink.net
Sun May 14 18:58:26 EDT 2006

The rabbit hole goes a bit deeper I'm afraid
y :: CDouble
y = 5.2
u :: Double
u = realToFrac(y)
test = do  printf "%14.7g" u 

Compiling Test             ( test.hs, interpreted )

    No instance for (PrintfType (t t1))
      arising from use of `printf' at test.hs:14:11-16
    Probable fix: add an instance declaration for (PrintfType (t t1))
    In the result of a 'do' expression: printf "%14.7g" u
    In the definition of `test': test = do printf "%14.7g" u
Failed, modules loaded: none.

But in fact just this, gives the same error
test = do  printf "%14.7g" 3.14 

Now in the command line I get errors under various configurations but a few
of them 
work e.g.
> printf "%g" u
> printf "%g" (3.14 :: Double)
do printf "%g" u
do printf "%g" (3.14 :: Double)

printf "%g" y -- y is  a CDouble
printf "%g" 3.14

All forms fail when compiled from a .hs file.  However, this just in!  I
finally got something to work,
namely this piece of code
test = do  (printf "%14.7g" (u  :: Double)) :: IO()

I guess the output of printf has to be disambiguated.  There should probably
be a few examples of this in the library documentation.  This also works, by
returning a string...
test = printf "%14.7g" (u  :: Double) :: String 

Thanks for the help by the way, without realtoFrac there would be no way for
me to use this at all.
View this message in context: http://www.nabble.com/CDouble-type-coercion-t1615450.html#a4385065
Sent from the Haskell - Haskell-Cafe forum at Nabble.com.

More information about the Haskell-Cafe mailing list