and the subject of the mail is because if actually give parameters to the print call I get a different error message, which is the first one I saw:
No instance for (MonadIO ((->) t0))
arising from a use of `TF.hprint'
Possible fix: add an instance declaration for (MonadIO ((->) t0))
but here I might be misusing the library in yet another way. I would first focus on the "no parameters" case.
Emmanuel
Hello,
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:
http://hackage.haskell.org/packages/archive/text-format/0.3.0.7/doc/html/Data-Text-Format.html
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 m, Params ps) => Handle -> Format -> ps -> m ()
while the type of hPrintf is:
hPrintf :: HPrintfType r => Handle -> String -> r
with the precision: The return type is restricted to (IO a).
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!
Emmanuel