
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
On Sat, Oct 20, 2012 at 8:24 PM, Emmanuel Touzery
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/Dat...
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 :: (MonadIOhttp://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Co...m, Paramshttp://hackage.haskell.org/packages/archive/text-format/0.3.0.7/doc/html/Dat...ps) => Handlehttp://hackage.haskell.org/packages/archive/base/4.4.1.0/doc/html/GHC-IO-Han...-> Formathttp://hackage.haskell.org/packages/archive/text-format/0.3.0.7/doc/html/Dat...-> ps -> m ()http://hackage.haskell.org/packages/archive/ghc-prim/0.2.0.0/doc/html/GHC-Un...
while the type of hPrintf is: hPrintfhttp://hackage.haskell.org/packages/archive/base/4.2.0.1/doc/html/Text-Print...:: HPrintfTypehttp://hackage.haskell.org/packages/archive/base/4.2.0.1/doc/html/Text-Print...r => Handlehttp://hackage.haskell.org/packages/archive/base/4.2.0.1/doc/html/GHC-IO-Han...-> Stringhttp://hackage.haskell.org/packages/archive/base/4.2.0.1/doc/html/Data-Char....-> r
with the precision: The return type is restricted to (IOhttp://hackage.haskell.org/packages/archive/base/4.2.0.1/doc/html/System-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