3 ms·
The 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
by BowBun 2y ago
The 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