TVTropes Now available in the app store!
Open

Follow TV Tropes

Following

Haskell

Go To

Comonad This bacon is awesome from 19th Jan '38 3:14:07 AM Since: Jan, 2001
This bacon is awesome
#1: Oct 23rd 2010 at 9:11:07 PM

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.
Tzetze DUMB from a converted church in Venice, Italy Since: Jan, 2001
DUMB
#2: Oct 23rd 2010 at 9:12:20 PM

Explain to me what the fuck monads are, please? I wanna stick with OCaml >_>

[1] This facsimile operated in part by synAC.
Comonad This bacon is awesome from 19th Jan '38 3:14:07 AM Since: Jan, 2001
This bacon is awesome
#3: Oct 23rd 2010 at 9:39:23 PM

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 to
    f a
  • m >>= return
    is equal to
    m
  • (m >>= f) >>= g
    is equal to
    m >>= (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 &lt; with <)

do
    x &lt;- f 1
    y &lt;- 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.
Tzetze DUMB from a converted church in Venice, Italy Since: Jan, 2001
DUMB
#4: Oct 26th 2010 at 10:59:09 PM

...uhhhhh...

Well thanks for trying. I'll continue trying to understand the concept.... ^_^;

[1] This facsimile operated in part by synAC.
Comonad This bacon is awesome from 19th Jan '38 3:14:07 AM Since: Jan, 2001
This bacon is awesome
#5: Oct 27th 2010 at 5:43:00 AM

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.
Add Post

Total posts: 5
Top