6 ms·
A Burrito Is a Monad
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- FrustratedMonky 2y agoIt's in jest, but I find a simple example like this to be very helpful. Would have gone a long way to me understanding Monads, rather than some esoteric mathematical symbols.
- spankalee 2y agoHonestly, I still don't get it. Which part is the monad? What's the example showing?
- BowBun 2y agoThe monad is the primitive/function that represents (VALUE or NULL), or in this case (CHICKEN or BEEF or ...). In this example, the ingredients and the burrito itself are also monads. If you type-check your Python/JS/Ruby code, monads are a functional-style solution to get rid of that code (functional programmers don't like type-checking). That's my simplest explanation at least!
- spankalee 2y agoWhich symbol or identifier in the code is the monad?
- loa_in_ 2y agoThe monad is none of the identifiers. If you combine the definitions you get a type with an interface equivalent to the monad and some floof methods (like the mission burrito starter, that's there just for convenience).
- bazoom42 2y agoThe Burrito type is the monad.
- chuckadams 2y agoIn the code example, it'd be `Burrito` along with the `>>=` operator and `return` function. In Haskell, Monad is the type class (more or less an Interface) that specifies the types of those functions, so anything that implements Monad is said to be "a monad". F# does not have type classes, so there's not one single thing to point to in that code as a monad, only the interface being implemented as a whole.
- burkaman 2y agotype Burrito is a monad, because the functions >>= and returnBurrito are defined. Any type for which those two functions are defined is a monad.
- 12345hn6789 2y agotype Burrito = Meat option \* Ingredient list let (>>=) burrito f = match burrito with | Some meat, ingredients -> f (Some meat, ingredients) | None, _ -> None, [] let returnBurrito (meat, ingredients) = meat, ingredients
- danielvf 2y agoMonads are just function chaining worshiped in the holy language of category theory. You have an array of state, and you can call a method on it that returns a new array of state, that you can call a method on, that returns a new array of state, etc. And that concept of doing state -> function call -> state is the holy Monad. A JS pleb would write instead: burrito = (new Tortilla()).addMeat(Chicken).addMissionBurritoIngredients().holdThe(Cheese) No one would be confused about what was going on, and it would be basically the same thing.
- FrustratedMonky 2y agoYes. But perhaps a syntax around the type of the return object to match with the next function. While it is just functions. To say, it's just functions all the way down, doesn't help you talk about them. Could say that math is all functions, and having some language to discuss that subject is maybe more the purpose of the monad. Kind of like if you were to say to a math student, just go study functions, no need for any school or language to describe what is happening. But yes, category theory is a bit heavy handed to a programmer just needing to chain some functions. Maybe the problem is such a vast gulf between the junior dev just needing to know how to chain some things, and the category mathematician that has never coded. Yet they are circling around the same subject.
- kelseyfrog 2y agoThis is literally, not figuratively, true. There's a lot of monads in our lives: puzzels, baking, stories, symphonies, paintings, and projects.
- tomerbd 2y agoMonad is mad
- mjd 2y agohttps://blog.plover.com/prog/burritos.html https://blog.plover.com/prog/burritos.html (Same concept, from 2009)
- pshirshov 2y agoNot this shit again. How much can be said about a trivial algebraic concept with 2 laws and 3 operations?
- rojotek 2y agoThis is my favourite comment on YCombinator and I had to reply to get a reminder.
- lapinot 2y agoI guess you meant 2 operations and 3 laws?
- bitwize 2y agoBecause grokking monads at some deep philosophical level is like "compiling the kernel" or "editing XF86Config": some mythically arcane thing you have to do that "only PhDs can understand" and hence is a good enough reason to avoid the thing it's a part of. Monads are a design pattern, albeit not one in the Gang of Four tradition, and it's concrete enough to be expressible in Haskell's type system. Learn the operations and laws, study some code involving List or IO to see how it's used, and get to work. No big deal.
- joev714 2y agoPeople who already know what a monad is probably think this is a great example. I still have no clue.
- miohtama 2y agoIt's a type of burrito
- chuckadams 2y agoIt's an endotaco in the category of fast food, what's the problem?
- burkaman 2y agoThis is an inside joke about people who write monad tutorials and think they've completely solved the issue by explaining that they're just like, for example, burritos: https://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/ https://byorgey.wordpress.com/2009/01/12/abstraction-intuiti...
- myhf 2y agomonad tutorials are monads
- burkaman 2y agoclass Monad (MonadTutorial badAnalogy) where return badAnalogy = MonadTutorial badAnalogy (MonadTutorial badAnalogy) >>= attemptToExplain = attemptToExplain badAnalogy attemptToExplain :: Analogy -> (MonadTutorial worseAnalogy) attemptToExplain analogy = MonadTutorial (makeItWorse analogy) Been like 10 years since I've used Haskell so I'm not totally sure this works but it was fun.
- zug_zug 2y agoA monad is a weird/unnecessary concept for a type that wraps another type (and makes certain guarantees). Like you can have a List<Int> so List is a monad type. There's also an "option" type in many languages (which is just a list of size 0 or 1), which is a monad. Some people call futures monads. But the real takeaway is that people pretend they want you to understand all this type stuff, but they don't, they want to make up new complicated words for obvious ideas that you already understand, so they can feel smart. Once you understand it they aren't "smarter" anymore, so they make sure to explain every weird term they made up with 5 other weird terms they made up and insisting that all this abstract theory is relevant to everybody when it's not.
- hrldcpr 2y agoMy Haskell is rusty—what does this line do? type Burrito = Meat option * Ingredient list Does `*` create a tuple type? Do lowercase `option` and `list` somehow specify `Option` and `List` types?
- antonyt 2y agoLooks more like F# (or something ML-y) than Haskell. Yep, tuple or "product type." Yep, in F# type annotations can be either in prefix style `List<T>` or postfix style `T list`.
- sieabahlpark 2y ago[dead]
- deleted 2y ago[deleted]
- chris_pie 2y agoI think this is F#, not Haskell. '*' creates a product type, pretty sure it's a tuple in this case. "Meat option" is an alternative syntax for "Option<Meat>" and "Ingredient list" is a linked list of Ingredients
- deleted 2y ago[deleted]
- mcbrit 2y agoYou are meant to feel it. Just: it does whatever is helpful.
- nkrisc 2y agoI assume that let tortilla = returnBurrito (Some Veggie, []) is a typo and it should be return Burrito ? Also somewhat familiar with FP but not this specific language (guessing Haskell?), is the `>==` operator essentially a "pipe" operator?
- hansonkd 2y ago`returnBurrito` is defined above it. `return` is a specific function of a Monad, and it is not used like the keyword "return" in other imperative languages.
- nkrisc 2y agoOh yeah, oops. I missed that.
- deleted 2y ago[deleted]
- chris_pie 2y agoThis is F#. >== is a bind operator, but it's not built into the language, so it's defined as a custom operator here. |> is a pipe
- bigstrat2003 2y agoOk Haskell programmers, I love you guys but this has now gone too far and I am officially intervening. The rest of the programming community and I are all super worried about what all this Haskell is doing for your health. Please stop before it's too late! Perhaps even touch grass, as drastic as I know that sounds.
- chuckadams 2y agoThe code is F#, not Haskell.
- numerate 2y agoOh, you think THIS is too far?
- mcbrit 2y agoNo one who cooks, cooks like this. So, no, a burrito is not a monad, unless you are performing Catholic Mass and the burrito is sth sth, in which case you have more words to write and I while I believe you can write those words, the words are not interesting. That it why I am saying your analogy is not interesting, and I think you were just attracted to burritos because they can hold.. anything? Even though that's not the path you went down?
- sophacles 2y agoHave you ever been to a burrito stand? Maybe a Chipotle restaurant? Literally the person assembling a burrito starts with tortilla and they add your meat and ingredients to it. The ingredients come from an array of pans at the counter (aka an enum of choices), and you (the consumer of said burrito) tell the maker what you want a series of "add this" type statements. I get that cooking is necessary to prepare the ingredients, but once the ingredients are all individually prepared, the cooking is irrelevant to making them into burritos.
- mcbrit 2y agoChipotle ensures all paths lead to a customer-pleasing Burrito, which is kind of sort of the same Burrito once you squint in the way Chipotle slants. Choose away; it does not matter very much. I would say cooking/Cooking is finding interesting variations of a Burrito. So while Chipotle may be explained as turning a Burrito into a Monad, a Burrito, and cooking a Burrito, is ideally not a Monad.
- deleted 2y ago[deleted]
- radium3d 2y agoRelegating "tortilla" to one word with no options is a travesty it's the most important part of my California Burritos from Juanitas.
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- l5870uoo9y 2y ago> You see, in addition to space burritos (if you've heard the rumors), monads are like onions. Allow me to demonstrate with a common situation. Another mention of monads and burritos. [0]: https://mostly-adequate.gitbook.io/mostly-adequate-guide/ch09#mixing-metaphors https://mostly-adequate.gitbook.io/mostly-adequate-guide/ch0...
- bckr 2y agoThe thing that has stuck with me about monads is that operations which you can chain like // Python new_foo = foo.bar().baz() Work as / can be defined as monads, if you get a Foo out of each of them. This at least gives me something practical to hang the concept on.
- beefnugs 2y agoPlease do see yourself out mr, I can't have multiple meats
- fanf2 2y agoPreviously: https://blog.plover.com/prog/burritos.html https://blog.plover.com/prog/burritos.html