[Haskell-cafe] Merry monad mixup?

David Menendez dave at zednenem.com
Fri Jan 28 20:36:52 CET 2011


On Fri, Jan 28, 2011 at 2:20 PM, michael rice <nowgate at yahoo.com> wrote:
>
> The first and third work, but not the second. Why?
>
> Michael
>
> ==============
>
> f :: String -> IO ()
> f s = do putStrLn s
>
> {-
> g :: [String] -> IO ()
> g l = do s <- l
>          putStrLn s
> -}
>
> {-
> h :: [Int] -> [Int]
> h l = do i <- l
>          return (i+1)
> -}

Written without the do-notation, your example is

g :: [String] -> IO ()
g l = l >>= \s -> putStrLn s

This won't work because (>>=) has type Monad m => m a -> (a -> m b) ->
m b, and your example requires m to be both [] and IO.


--
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>



More information about the Haskell-Cafe mailing list