4 ms·
Which symbol or identifier in the code is the monad?
by spankalee 2y ago
Which 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