Die Maybe-Monade

data Maybe a = Nothing | Just a
instance Monad Maybe where ...
Beispiel-Anwendung:
case ( evaluate e l ) of
    Nothing -> Nothing
    Just a  -> case ( evaluate e r ) of
        Nothing -> Nothing
        Just b  -> Just ( a + b )
mittels der Monad-Instanz von Maybe:
evaluate e l >>= \ a ->
    evaluate e r >>= \ b ->
        return ( a + b)
Ü: dasselbe mit do-Notation

Johannes Waldmann 2014-03-31