6 ms·
So, to see if I'm understanding: is the purpose of the Maybe monad to abstract the concept of "evaluate to Nothing if the previous expression evaluated to nothi
by ericwaller 17y ago
So, to see if I'm understanding: is the purpose of the Maybe monad to abstract the concept of "evaluate to Nothing if the previous expression evaluated to nothing?" Also, is 'build'/'return' being used implicity somewhere?
- jmillikin 17y agois the purpose of the Maybe monad to abstract the concept of "evaluate to Nothing if the previous expression evaluated to nothing? Exactly. It's a data type for short-circuiting. Also, is 'build'/'return' being used implicity somewhere? Not in this example -- I thought about it, but ultimately decided additional changes between examples would just confuse things. It's worth including in the definition because it's one of the two fundamental operations. In real code, it's mostly used when the exact monad being used isn't specified. For example, here's a function which runs a monadic computation until it returns `False'. The result is `()', sort of a Haskell void type. runUntil :: Monad m => m Bool -> m () runUntil comp = loop where loop = do x <- comp if x then loop else return () Not useful for `Maybe', but stateful monads like `State', `Get', `Put', or `IO' could all be used on it reasonably.