[Haskell-beginners] no instance for monad

Emmanuel Touzery etouzery at gmail.com
Sat Oct 20 20:24:29 CEST 2012


 in my program i have a function which can be simplified like this:

 writeProgramInfo :: Handle -> ProgramInfo -> IO ()
 writeProgramInfo handle program = do
        hPrintf handle "hello"

This is using the hPrintf from Text.Printf.

Unfortunately that hPrintf works on String parameters which is not good
enough because I need unicode character support (if I use unpack it works
on linux but complains about invalid characters on windows, I guess because
my locale on linux is utf-8 but on windows it's a local codepage). So I
found the Text.Format library:

 Which appears to solve exactly that problem (out of the box Text support).
However I can't just install the library, add the import statements, and
replace hPrintf by TF.hprint and change the format string, that doesn't
work; if I change this function to:

import qualified Data.Text.Format as TF

writeProgramInfo :: Handle -> ProgramInfo -> IO ()
writeProgramInfo handle program = do
        TF.hprint handle "hello"

I get this error message at build time:

Couldn't match expected type `IO ()'
                with actual type `ps0 -> m0 ()'
    In the return type of a call of `TF.hprint'
    In the expression: TF.hprint handle "hello"
    In the expression: do { TF.hprint handle "hello" }

Now this clearly results from the type of hprint, which is:
hprint :: (MonadIO<http://hackage.haskell.org/packages/archive/transformers/>m,
ps -> m

 while the type of hPrintf is:

 with the precision: The return type is restricted to

 Well I didn't completely 'get' the monad thing yet. I think I'm pretty
close.. but not there yet. I'm pretty sure understanding this specific
example will take me one step closer... What am I missing here?

 Thank you!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121020/d2617405/attachment.htm>

More information about the Beginners mailing list