[Haskell-beginners] no instance for monad

Daniel Trstenjak daniel.trstenjak at gmail.com
Sat Oct 20 21:46:21 CEST 2012


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



More information about the Beginners mailing list