[Haskell-cafe] Re: Tutorial uploaded

Peter Simons simons at cryp.to
Tue Dec 20 14:58:05 EST 2005


Daniel Carrera writes:

 > I'm scared of monads :) I really don't know what a monad
 > is.

Neither do I, but that doesn't mean that I can't use just
fine. ;-)


 >> putStrLn :: String -> World -> World
 >
 > That seems less scary.

Things become a lot clearer when you think about how to
print _two_ lines with that kind of function. You'd write:

  f :: World -> World
  f world = putStrLn "second line" (putStrLn "first line" world)

The 'world' parameter forces the two functions into the
order you want, because printing "second line" needs the
result of printing "first line" before it can be evaluated.

However, writing complex applications with that kind of API
would drive you nuts, so instead you can say

  f :: IO ()
  f = do putStrLn "first line"
         putStrLn "second line"

and it means the exact same thing.

Curiously enough, if you check out the reference
documentation at:

  http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad-ST.html#t%3ARealWorld

..., you'll find that a "World" type actually exists.

Peter



More information about the Haskell-Cafe mailing list