Skip to content

Instantly share code, notes, and snippets.

@icidasset
Last active July 14, 2016 11:16
Show Gist options
  • Save icidasset/66e84414df6a22550995facfe4a7a4e8 to your computer and use it in GitHub Desktop.
Save icidasset/66e84414df6a22550995facfe4a7a4e8 to your computer and use it in GitHub Desktop.

Monads

  • Value, object.
  • Data constructor, a box or a ghost box.
  • Type constructor, a set of boxes.
  • Type classes, classes of people who have a certain set of skills.

Clarification of ghost boxes:
They look like boxes, but actually you can directly touch the object inside them.
That is, the box is an illusion.

Maybe

Example set of boxes MAYBE:

  • box Just
  • box Nothing

Functor

Each class of people is trained to handle a box in a certain way.
Let's take a look at the people class FUNCTORS, skill set:

  • skill fmap, description: execute an action on a box

For example, when a functor performs an fmap on a Just box,
he first opens the box, then executes the action on the item in the box,
then takes a new box of the same type and puts the item in the new box.

And when he performs an fmap on a Nothing box,
he just takes a new Nothing box, nothing more.

Monad

Let's look at another class of people, called MONADS,
these people have been mentored by the functors,
so they possess the same basic skillset:

  • skill >>=, description: take a box and a box-producing machine,
    and do something with those things

When a monad receives a Just box, he knows that he first has to open the box,
get the item out of it and then put it in the machine.

Like the functor, when a monad receives a Nothing box,
he just takes a new Nothing box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment