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

Lets get concrete and make a simple example State monad.

You have access to an extra variable S, with getS and setS, and each of those return values of our StateMonad.

Using these (and >>= aka bind) you can write something which increments the number in the state by one, yes?

    increment = do s <- getS
                   setS (s+1)
and this increment is a value of our StateMonad.

This doesn't run on it's own though, it needs the "interpreter" to run the state monad, and put in a initial value of the state, and maybe take it out at the end.

That's the way you can think of Monads as interpreters in a very rough sense.

Now, you can do fancier things, where you can set up a "free monad", which is basically going to record everything into a syntax tree, and then you really have an interpreter.

http://blog.sigfpe.com/2006/08/you-could-have-invented-monad...




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: