Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
More monads in OCaml (haberkucharsky.com)
17 points by jhaberku on July 22, 2015 | hide | past | favorite | 3 comments


One of my favorite monad rants

https://existentialtype.wordpress.com/2011/05/01/of-course-m...

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!


> 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


Prof. Harper does have some wonderfully entertaining rants on that site.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: