[Haskell-cafe] howto mix <- within do?

Dougal Stanton dougal at dougalstanton.net
Fri Oct 17 08:57:11 EDT 2008


On Fri, Oct 17, 2008 at 1:39 PM, Larry Evans <cppljevans at suddenlink.net> wrote:
> do_with_assignment.proto.hs:30:2:
>    Couldn't match expected type `[]' against inferred type `IO'
>      Expected type: [t]
>      Inferred type: IO ()
>    In the expression: putStr "v0="
>    In a 'do' expression: putStr "v0="

Prelude> let f = do { v <- [999] ; return () }
Prelude> :t f
f :: [()]
Prelude> :t putStr ""
putStr "" :: IO ()


So "v <- [999]" is in the list monad, but putStr is in the IO monad.
The two cannot mix in that way.

This looks like it might be homework so I'll refrain from saying any
more for now. Good luck!


D


More information about the Haskell-Cafe mailing list