[Haskell-beginners] no instance for monad

Emmanuel Touzery etouzery at gmail.com
Sat Oct 20 20:26:44 CEST 2012

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.


On Sat, Oct 20, 2012 at 8:24 PM, Emmanuel Touzery <etouzery at gmail.com>wrote:

> 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/
>  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,
> Params<http://hackage.haskell.org/packages/archive/text-format/>ps) =>
> Handle<http://hackage.haskell.org/packages/archive/base/>->
> Format<http://hackage.haskell.org/packages/archive/text-format/>-> ps -> m
> ()<http://hackage.haskell.org/packages/archive/ghc-prim/>
>  while the type of hPrintf is:
> hPrintf<http://hackage.haskell.org/packages/archive/base/>::
> HPrintfType<http://hackage.haskell.org/packages/archive/base/>r =>
> Handle<http://hackage.haskell.org/packages/archive/base/>->
> String<http://hackage.haskell.org/packages/archive/base/>-> r
>  with the precision: The return type is restricted to (IO<http://hackage.haskell.org/packages/archive/base/>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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121020/f2bbaedc/attachment.htm>

More information about the Beginners mailing list