[Haskell-cafe] CDouble type coercion

SevenThunders mattcbro at earthlink.net
Sun May 14 15:00:55 EDT 2006

Thanks that helps a bit.  The realToFrac type coercion works, but ultimately
it seems 
that printf won't play nice.  Consider this simple haskell code

module Test
import IO
-- import Data.Array.Storable 
import Text.Printf
import Foreign.C.Types (CInt, CDouble )

y :: CDouble
y = 5.2
u = realToFrac(y)
test = do  printf "%14.7g" u   

Compiling it into GHCi I get the error,
    No instance for (PrintfType (t t1))
      arising from use of `printf' at test.hs:13: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.

If I replace the printf by a standard print there is no problem.  Also if I
comment out
the line with test = ... , it will load (compile) and I can then type in the
printf "%14.7g" u 
and it works!

printf "%14.7g" y

fails because y is of type CDouble.  At this point I think I'm giving up on
formatted printing in Haskell.  It's just too persnickety. 
I guess I'll just call printf via C and see what happens.

View this message in context: http://www.nabble.com/CDouble-type-coercion-t1615450.html#a4383006
Sent from the Haskell - Haskell-Cafe forum at Nabble.com.

More information about the Haskell-Cafe mailing list