Hacker News new | past | comments | ask | show | jobs | submit login

Aye, but minus the low level features of C and the high level features of Lisp. Like pointer and memory manipulation and macros.

Still, it can be a very nice language, I just wouldn't say it is "C + Lisp". Also I'm not sure what the article had to do with either Lisp or C, it seemed more like a discussion of haskell... Am I missing something?

Edit: I'm still confused. Anyone want to take a better shot at explaining what a monad is? Or, more precisely, what's so special about it that it deserves a special name?




A monad is a kind of control structure between functions. Kind of like if you could overload add extra hook functionality to the Unix shell pipe, besides just piping stuff along. For instance, seed it with a countdown, and every time stuff is piped to another process, see how much time has elapsed; if at any point it's been more than, say, 30 seconds, just stop the whole series and return an error. Or find a path through a maze by backtracking every time it hits a dead end, returning to the most recent unexplored path.

They're a necessary workaround to do some stuff in pure functional languages (which is why Haskell users make such a big deal out of them), but you can do some really cool tricks with them.

(NB: This is a really vague summary. I found this OCaml-based monad intro helpful, because it mostly avoids entangling the monad concepts with unrelated issues in Haskell. http://enfranchisedmind.com/blog/2007/08/06/a-monad-tutorial... There's a good Monads-in-Scheme intro, too, I forget where.)


"They're a necessary workaround to do some stuff in pure functional languages"

This isn't actually true. You can still write imperative programs in a pure FP language. The most obvious way is to write your code in continuation passing style and pass the new state of the world to each continuation; taking the implicit state changes of an imperative language and making them explicit.

The real reason for using monads is that the scheme I just described is inhumanly complicated. Monads are a much more structured way of doing the same thing. Instead of writing these state passing CPS functions, you write functions that build them for you. A consequence of this is that monads perform much the same function as macros in Lisp; they are programs that build programs.


Agreed. I guess I should have added, "without making things unnecessarily complicated.".

I think that monads, too, are generally presented in a way that makes them more complicated than they really are. (Hence, I suppose, SPJ's comment about how they should have been called "warm fuzzy things".) Part of my trouble understanding them confronting the basics of Haskell at the same time, and I (along with much of what I read) focused on the IO monad. That's probably one of the most complicated ones. The ideas started to click when I switched to the Maybe monad -- not only is that one considerably more straightforward, but I (and probably many others) had already written essentially the same construct elsewhere, albeit without the formal notation.


A monad is a means by which people who are pedantically attached to the notion of pure functional programming can write programs that /actually do something/ while still claiming that they're functional.


Monad is the name for an algebraic structure, the same way that 'field' and 'group' and 'monoid' and 'integral domain' and 'vector space' are names for algebraic structures.

In particular it's useful for actions. It has only two functions, 'return' and '>>=':

    (return x)    -- an action that returns the value x

    (a >>= f)     -- the action produced by attaching the
                  -- continuation f to the action a
It is the algebraic structure of attaching continuations to things.




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

Search: