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

Tony Morris tonymorris at gmail.com
Sun Mar 15 21:17:33 UTC 2015


Scalaz implements IO and ST as a library for Scala.

http://eed3si9n.com/learning-scalaz/IO+Monad.html

On 16/03/15 02:17, Simon Kitching wrote:
> [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
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



More information about the Beginners mailing list