What is a monad?

Coders forum. Discuss techniques, swap code snippets, ask for help etc. relating to all forms of software development.
User avatar
teamonkey
Sheepie Whore
Sheepie Whore
Posts: 12082
Joined: Thu Jun 13, 2002 1:07 am 0
XBL Gamertag: itsthetaste
PSN: teamonkey_ca
Contact:

What is a monad?

Post by teamonkey »

I know they're a way of wrapping up side effects in a "warm fuzzy thing" but I don't know how or why they work or in fact what they actually do.

I've looked at lots of references but haven't found a single good explanation. There's lots of info about how they apply to Haskell but it's all useless unless you can decode Haskell's esoteric syntax (which I haven't got round to learning yet). Most of the other tutorials are along the lines of "here's how we do it in Haskell, now this is how we implement it in some other language," which, again, is useless unless you know what they do in Haskell.

So can anyone help? This isn't for anything in particular, I'm just curious. :)
User avatar
lis0r
Baaaa!
Baaaa!
Posts: 894
Joined: Tue Jan 10, 2006 9:26 am 0
Location: The Frozen Wastelands Of The North

Re: What is a monad?

Post by lis0r »

teamonkey wrote:So can anyone help? This isn't for anything in particular, I'm just curious. :)
I can't quite fathom it myself, but they appear to be some functional language gymnastics so you can change the value of something without mutating it (considered cheating) or passing it around (considered tedious).

i.e. they're fuck all use in the real world, since it's much easier to mutate, or just not use a functional language in the first place :wink:
Last edited by lis0r on Tue Oct 09, 2007 3:53 pm 0, edited 1 time in total.
User avatar
l1n3n01z
Baaaaa!
Baaaaa!
Posts: 1777
Joined: Tue Nov 19, 2002 12:14 pm 0
Location: Iceland
Contact:

Post by l1n3n01z »

User avatar
fred_zen
Baaaa!
Baaaa!
Posts: 743
Joined: Mon Jun 26, 2006 3:15 pm 0
Location: France

Post by fred_zen »

If you really want to know, http://citeseer.ist.psu.edu/62964.html . Category theory is not genuinely difficult but... really warped... you have to look at it from the right angle. Sometimes I have "aha" moments where everything looks very plain and simple. Most of the time it just gives me headaches.

Edit: Ooh, nice link, Linenoize !
User avatar
foxyloxy
Baaa!
Baaa!
Posts: 311
Joined: Fri Jun 21, 2002 4:15 am 0
Location: UK, Manchester

Post by foxyloxy »

I couldn't visualise monad binding until I learned to crochet, then it was easy :) That and writing compilers (well, the parser parts, and maybe SSA optimisers which are currently doing my head in).


<edit> Oh, and looksee at these neat tutorials http://lambda-the-ultimate.org/node/2455.
User avatar
moosedude
Baaaaaaa!
Baaaaaaa!
Posts: 6209
Joined: Fri Nov 19, 2004 1:19 pm 0
Location: Craggy Island
Contact:

Post by moosedude »

Didn't hitler have a monad?

/coat

01000101 01000100 01000111 01000101

http://www.redbubble.com/people/fotofill/ buy my photos!
User avatar
teamonkey
Sheepie Whore
Sheepie Whore
Posts: 12082
Joined: Thu Jun 13, 2002 1:07 am 0
XBL Gamertag: itsthetaste
PSN: teamonkey_ca
Contact:

Post by teamonkey »

foxyloxy wrote:I couldn't visualise monad binding until I learned to crochet, then it was easy :) That and writing compilers (well, the parser parts, and maybe SSA optimisers which are currently doing my head in).
If only I'd read this last night. My wool-obsessed fiancee was trying to teach me to crochet and I was actively dissuading her. :)
User avatar
GoatFoam
Baaaaa!
Baaaaa!
Posts: 1255
Joined: Tue Dec 12, 2006 11:05 am 0
Location: Brizzle
Contact:

Post by GoatFoam »

foxyloxy wrote: <edit> Oh, and looksee at these neat tutorials http://lambda-the-ultimate.org/node/2455.
Cheers. That should be pretty handy.

The ruby one was no good to me as I can't get through that bloody ruby tutorial without wanting to put my fist through the screen. It IS NOT FUNNY.

Right, now I have got that off my chest.
User avatar
l1n3n01z
Baaaaa!
Baaaaa!
Posts: 1777
Joined: Tue Nov 19, 2002 12:14 pm 0
Location: Iceland
Contact:

Post by l1n3n01z »

GoatFoam wrote:
foxyloxy wrote: <edit> Oh, and looksee at these neat tutorials http://lambda-the-ultimate.org/node/2455.
Cheers. That should be pretty handy.

The ruby one was no good to me as I can't get through that bloody ruby tutorial without wanting to put my fist through the screen. It IS NOT FUNNY.

Right, now I have got that off my chest.
:lol: :lol:
User avatar
tufty
Sheepie Whore
Sheepie Whore
Posts: 12524
Joined: Fri Jan 07, 2005 4:52 pm 0
Location: French Alps

Post by tufty »

GoatFoam wrote:The ruby one was no good to me as I can't get through that bloody ruby tutorial without wanting to put my fist through the screen. It IS NOT FUNNY.
Yep, I feel much the same; although it showed more or less how to set up a monad in Ruby it completely irritated me.

I can see how they work, but I'm still unsure what monads are actually good for, though. Maybe I'm being dumb, or maybe I should learn to crochet.

Simon
"massive retard™", "full of shit™", "tiny bitch™", "retarted™", "a bit of a one trick pony™", "petty™", "simple minded idealistic twat™", "miserable humourless fucker™"
User avatar
l1n3n01z
Baaaaa!
Baaaaa!
Posts: 1777
Joined: Tue Nov 19, 2002 12:14 pm 0
Location: Iceland
Contact:

Post by l1n3n01z »

tufty wrote:
GoatFoam wrote:The ruby one was no good to me as I can't get through that bloody ruby tutorial without wanting to put my fist through the screen. It IS NOT FUNNY.
Yep, I feel much the same; although it showed more or less how to set up a monad in Ruby it completely irritated me.

I can see how they work, but I'm still unsure what monads are actually good for, though. Maybe I'm being dumb, or maybe I should learn to crochet.

Simon
I know some knitting, but that only helped me with Metaclasses.
Needlepoint is good for when you are just getting into closures and higher order functions, and quilting is great for continuations, co-routines and their ilk.
User avatar
lis0r
Baaaa!
Baaaa!
Posts: 894
Joined: Tue Jan 10, 2006 9:26 am 0
Location: The Frozen Wastelands Of The North

Post by lis0r »

tufty wrote:I can see how they work, but I'm still unsure what monads are actually good for, though. Maybe I'm being dumb, or maybe I should learn to crochet.
In a purely functional language, you can't usually guarantee the order of evaluation, hence the order of side effects. If the order matters (e.g. I/O), you're screwed. Monads provide this guarantee.

i.e. they're bloody useless in most languages.
User avatar
l1n3n01z
Baaaaa!
Baaaaa!
Posts: 1777
Joined: Tue Nov 19, 2002 12:14 pm 0
Location: Iceland
Contact:

Post by l1n3n01z »

Too bad about the sound quality :-/
User avatar
l1n3n01z
Baaaaa!
Baaaaa!
Posts: 1777
Joined: Tue Nov 19, 2002 12:14 pm 0
Location: Iceland
Contact:

Post by l1n3n01z »

One thing that I've been wondering about. Doesn't Haskell have closures? How is that compatible with being a pure functional programming language? Or does it only close over functions?
User avatar
l1n3n01z
Baaaaa!
Baaaaa!
Posts: 1777
Joined: Tue Nov 19, 2002 12:14 pm 0
Location: Iceland
Contact:

Post by l1n3n01z »

Post Reply