

More monads in OCaml - jhaberku
http://blog.haberkucharsky.com/technology/2015/07/21/more-monads-in-ocaml.html

======
saosebastiao
One of my favorite monad rants

[https://existentialtype.wordpress.com/2011/05/01/of-
course-m...](https://existentialtype.wordpress.com/2011/05/01/of-course-ml-
has-monads/)

 _My point is that the ML module system can be deployed by you to impose the
sorts of effect segregation imposed on you by default in Haskell. There is
nothing special about Haskell that makes this possible, and nothing special
about ML that inhibits it. It’s all a mode of use of modules.

So why don’t we do this by default? Because it’s not such a great idea. Yes, I
know it sounds wonderful at first, but then you realize that it’s pretty
horrible. Once you’re in the IO monad, you’re stuck there forever, and are
reduced to Algol-style imperative programming. You cannot easily convert
between functional and monadic style without a radical restructuring of code.
And you are deprived of the useful concept of a benign effect.

The moral of the story is that of course ML “has monads”, just like Haskell.
Whether you want to use them is up to you; they are just as useful, and just
as annoying, in ML as they are in Haskell. But they are not forced on you by
the language designers!_

~~~
codygman
> You cannot easily convert between functional and monadic style without a
> radical restructuring of code.

Yes you can, though you do it backwards from what many people expect. Instead
of getting something out of IO why not put the pure function into IO?

This can be done with liftM and fmap.

    
    
        > let x = return 1 :: IO Int
        > let z = fmap (+ 1) x
        > z
        2
        > :type z
        z :: IO Int

