11 July 2020 - 2 min read

Is a burrito a monad?

As we all know, a monad is just a monoid in the category of endofunctors. This is intuitive to you and I, but what if you need to explain what a monad is in more practical terms. Well that's where the three laws of monads come in.

These three laws act as a test to tell if something is a monad - if that something passes the three laws, then it's a monad -- simples.

Now to the main event, is a burrito monad? Well let's see if it obeys the three laws...

Left identity

Take your filling, put it in a burrito - toast it - take the filling back out - the filling is warm just as if you toasted the filling itself.

So the burrito passes the first law.

Right identity

Unwrap the burrito to get to the filling.

The burrito passes the second law.

Associativity

Putting hot sauce in your burrito and then toasting it is the same as toasting it and putting hot sauce in your burrito.

Thus the burrito passes the third law.

The burrito is a monad 🌯

Further reading

Burritos for the Hungry Mathematician by Ed Morehouse


Discuss this post in the GitHub discussion or on Twitter.

Tom Sherman

Hey 👋 I'm Tom, a Software Engineer from the UK.

I'm currently a Software Engineer at OVO Energy. I'm super into the web, functional programming, and strong type systems.

You can most easily contact me on Mastodon but I'm also on Twitter, LinkedIn, and GitHub.