Explain to me what the fuck monads are, please? I wanna stick with OCaml >_>
[1] This facsimile operated in part by synAC.Sure, but understanding how they actually relate to programming just from reading a description is hard.
A monad is a type class m that has the following functions defined on it:
- x >>= y, where x is of type m a and y is a function from a to m b. Returns a value of type m b.
- return x, where x is of type a. Returns a value of type m a.
The functions have to follow these rules:
-
(return a) >>= f
is equal tof a
-
m >>= return
is equal tom
-
(m >>= f) >>= g
is equal tom >>= (f >>= g)
You can use syntactic sugar to string a bunch of >>= together and do... lots of things. For example, if you're using the list monad, and f and g model nondeterministic functions by returning a list of possible values, you can do this:
(My formatting-fu is not strong, so replace the < with <)
do
x <- f 1
y <- g x
return y + 2
Which expands to
f 1 >>= (g >>= (\\y -> return y + 2))
which ends up doing what the code above looks like it should do.
(I made a bunch of errors typing that up. I think they're all fixed now.)
edited 23rd Oct '10 11:18:01 PM by Comonad
Torment liveblog is still hiatusing. You can vandalize my contributor page if you want something to do....uhhhhh...
Well thanks for trying. I'll continue trying to understand the concept.... ^_^;
[1] This facsimile operated in part by synAC.Yeah, I read a bunch of monad tutorials and had no idea. You may just have to write a monad yourself.
Torment liveblog is still hiatusing. You can vandalize my contributor page if you want something to do.

What's this "monad" thing? ...huh? I don't understand any of this.
A few weeks later:
Huh, so this type signature is a more specific form of that one, which means I can replace that function I wrote with this preexisting one, and MY GOD IT'S FULL OF STARS I THINK I JUST INVENTED TIME
Yes, this is where my username came from. No, I don't really understand what a comonad is yet.
Torment liveblog is still hiatusing. You can vandalize my contributor page if you want something to do.