# Programming

2 thoughts
last posted July 12, 2015, 8:06 a.m.

1 earlier thought

0

Contrast with Haskell itself, where what happens is that the IO monad acts as a decorator turning all your functions that (say for [readline[(https://hackage.haskell.org/package/readline-1.0.1.0/docs/System-Console-Readline.html#v:readline)) take a string and return a string, and wraps them up so that they take and return a RealWorld parameter as well - but this gets optimised out by the compiler, and the coolness of Monads is they also get optimised out of the source code :). But its this threading of a hypothetical data parameter through all the functions (including recursively defined ones) that gives you ordering, and lets you write 'imperative' code in a purely functional language. You never see RealWorld in function definitions because the the type of the function is input1, ..., inputN -> IO (output), but return binds it in via State. If you look closely, you'll see that IO String actually holds a function parameterised by String. IO (State# RealWorld -> (State# RealWorld, String)) - the extra input T and output T in (T,a) are supplied entirely by the monad instance. So all the machinery is doing is letting you say 'this into that into other thing' without having to manually express data dependencies. Something that Python doesn't need at all (because it isn't lazy, things are always evaluated.