
Of Course ML Has Monads - ottbot
http://existentialtype.wordpress.com/2011/05/01/of-course-ml-has-monads/
======
Peaker
> The default basis library does not attempt to segregate effects into a
> monad, but it is perfectly straightforward to do this yourself, by providing
> your own layer over the standard basis

This comment is somewhat silly. The whole notion of segregating effects is
about what a programmer _cannot_ do, and not about what they can.

In ML, maybe _you_ can segregate effects, but it is of limited value, as all
of the code you use _might_ be hiding procedural effects behind the seemingly
innocent types.

In Haskell, when I read an API, I _know_ no effects lurk behind the pure type
signatures.

~~~
enum
> In Haskell, when I read an API, I know no effects lurk behind the pure type
> signatures.

I wonder how often unsafePerformIO : IO 'a -> 'a is employed

~~~
baguasquirrel
unsafePerformIO is not nearly as useful for introducing effects as one might
think it would be. Because Haskell is lazy, any effects you might want would
have to be grounded in the toplevel IO monad anyway.

To answer you directly, I've read code in various Haskell packages, everything
from mime to snap, and AFAICT, it is typically used when you need to call a C
library. Suppose you need to use OpenSSL's digest algorithms, for example.
Because we technically don't know whether or not that library will have
effects, we have to use unsafePerformIO.

~~~
eru
Actually you can interpret unsafePerformIO as: "Dear compiler, I know you
can't prove that it's safe to call this function here in a lazy setting.
Please trust me that it is. Sincerely, the programmer."

~~~
dons
Precisely. The burden is on the programmer to provide the evidence that the
conditions for calling `unsafePerformIO` are satisfied. (That is, that any
side effects are hidden).

Most languages have `unsafePerformIO` on every single computation :-)

~~~
baguasquirrel
It's like there's a spacesuit full of nuclear waste in every single
computation!

~~~
dons
_The horror!!_

------
abecedarius
You could analogously explain how of course Lisp has types, you just implement
Hindley-Milner and slot it in in front of the standard library. Only, if the
author wrote _that_ , I'd think I was hallucinating.

------
colanderman
Also of note, a syntax extension for OCaml adding do-notation to the language:
<http://www.cas.mcmaster.ca/~carette/pa_monad/>

