Die Konstruktorklasse Monad

class Monad c where
    return  :: a -> c a
    ( >>= ) :: c a -> (a -> c b) -> c b

instance Monad Maybe where
    return = \ x -> Just x
    m >>= f = case m of
        Nothing -> Nothing
        Just x  -> f x

instance Monad [] where
    return = \ x -> [x]
    m >>= f = concat ( map f m )



Johannes Waldmann 2011-01-18