Stupid wuestion about Monads :)

Marc Ziegert coeus@gmx.de
Thu, 12 Jun 2003 00:10:22 +0200


google: "What the hell are Monads"
http://www.abercrombiegroup.co.uk/~noel/research/monads.html

IO in haskell is really easy, iff you understand the sense of monads.

to understand sth. like "IO Bool" you have to remember that i.e. an array=
 is no defined data type without the definition of its entries.
"[Bool]" is sth. like that, too. the data type does not contain one "[]" =
and one "Bool".

"IO a" is in fact an Input-Output-operation with return type "a".
imagine this:
"State -> (State,a)" the world state changes and there is an "a" as resul=
t part. it is not possible (mathematical, not technical) to throw away th=
e fact that it is a function changing the state.

your main function is of type...

main :: IO ()

where "()" means sth. like "void".
the IOs have just to be concatenated to construct a program.

main :: IO ()
main =3D putStr "Hello "
       >> return "world!"
       >>=3D putStrLn
       >> getChar
       >>=3D (\c -> putStrLn [c,c,c])
       >> return ()

you have to write a line and press <Return>, then getChar reads the first=
 Char of your line.