Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The short answer is category theoretic monads. Once upon a time, Eugenio Moggi realized that monads could be used as the formal basis for assembling sequential actions. For example, when you write

    print("hello ");
    print("world")
you expect the output to be "hello world" and not "worldhello " or something weirder. Moggi realized that the semicolon there was a monadic operation that arranged for the two outputs to be printed sequentially.

That might seem like a small thing, but it isn't. In theory, so far as I understand, specifically in denotational semantics, the next best alternative is continuation passing, which adds an extra parameter and return value to the actions and is generally awkward.

The big advantage, though, is practically, in lazy programming languages like Haskell. In that case, the alternative was world passing, where the entire (metaphorical) universe is passed to the action to allow normal parameter passing conventions to sequentially associate the actions. (In contrast, monadic IO does the same thing, but hides the world in the definition of the monad.) The result is sequential code that we all know and love.

Then it was discovered that other bases than the (metaphorical) IO world made for meaningful, useful monads: the maybe monad aborts a computation on the first error, for example. And other data structures like lists...well, go look for a paper with a title like "turn your failures into a list of successes" and we were off and running.

[Edit]

And I'm thinking of the wrong Wadler paper. Try some of the ones from here [1], starting at the bottom.

[1] http://homepages.inf.ed.ac.uk/wadler/topics/monads.html



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

Search: