[Haskell-beginners] Equivalent of IO Monad in other functional languages?

Simon Kitching simon at vonos.net
Sun Mar 15 16:17:17 UTC 2015


[Note: learning haskell, not familiar with other functional languages]

I have a question about handling impure operations in functional or 
semi-functional languages other than Haskell (eg OCaml, F#, Scala, ..).

Haskell uses the IO monad to (a) cleanly separate pure and impure code, 
and (b) prevent function-calls from being reordered when they have 
side-effects that must happen in the right order. How do other languages 
handle this?

AIUI, whether a Haskell function is 'pure' or not can be seen from its 
method signature : if it returns IO then it is impure. All standard 
library functions that have side-effects (read/write/etc) return IO, and 
any function that uses an IO value must return type IO. Do other 
functional languages (1) use a similar approach, or (2) not provide a 
way to be certain that a function is 'pure' (side-effect-free)?

And AIUI the Haskell compiler/runtime can postpone evaluation of any 
function (laziness), or reorder function calls whever it thinks this 
good. However using the monad design pattern (deliberately) prevents 
this (each operation passes its value as a parameter to the subsequent 
operation, thus forcing an order of evaluation). Do other languages (a) 
not support compiler/runtime reordering of functions, or (b) have some 
other way of preventing functions with side-effects from being reordered?

Thanks..
Simon


More information about the Beginners mailing list