Semantik (mit Maybe)

data Expression = ... | Reference Identifier
evaluate 
    :: Environment -> Expression -> Integer ??
    :: Environment -> Expression -> Maybe Integer
evaluate e x = case x of 
    Reference i -> M.lookup i e
    Plus l r -> case ( evaluate e l ) of
        Nothing -> Nothing
        Just a  -> case ( evaluate e r ) of
            Nothing -> Nothing
            Just b  -> Just ( a + b )
das schöner hinschreiben mit Monaden und do-Notation



2009-11-20