[Haskell-beginners] no instance for monad

Emmanuel Touzery etouzery at gmail.com
Sat Oct 20 21:53:09 CEST 2012


Thank you! And yes that works...

But what if i do want to give several parameters to hprint? In my second
email i noted i get a different error message in that case?
so for instance:
TF.hprint handle " {} {}" "a" "b"

In that case I get that "no instance for.." error message.

    No instance for (MonadIO ((->) t0))
      arising from a use of `TF.hprint'
    Possible fix: add an instance declaration for (MonadIO ((->) t0))
    In the expression: TF.hprint handle " {} {}" "a" "b"
    In the expression: do { TF.hprint handle " {} {}" "a" "b" }
    In an equation for `writeProgramInfo':
        writeProgramInfo handle program
          = do { TF.hprint handle " {} {}" "a" "b" }


On 20 Oct 2012 21:48, "Daniel Trstenjak" <daniel.trstenjak at gmail.com> wrote:

>
> Hi Emmanuel,
>
> > 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" }
>
> GHC expects an expression of 'IO ()' - the return type of writeProgramInfo
> -
> but the expression 'TF.hprint handle "hello"' has the type 'ps0 -> m0 ()'
>
> Look at the type of 'hprint':
> hprint :: (MonadIO m, Params ps) => Handle -> Format -> ps -> m ()
>
> Your call of 'hprint' is missing the last argument, the 'ps'. So
> instead of 'm ()' you're returing the function 'ps -> m()', that's
> what GHC tries to tell you.
>
>
> You might be confused, because 'hprintf' uses some magic to allow
> multiple parameters and can even be called without any parameter.
>
> 'hprint' uses are more explict - and imho a nicer and simpler approach -
> for the parameters, but the parameter can't be completly omitted,
> it has to be at least '()'.
>
> So in your case: TF.hprint handle "hello" ()
>
>
> Greetings,
> Daniel
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121020/203f19bc/attachment.htm>


More information about the Beginners mailing list