Monadisches Verketten von Parsern

instance Monad ( Parser c ) where
    return x = Parser $ \ s -> 
        return ( x, s ) 
    Parser f >>= g = Parser $ \ s -> do
        ( a, t ) <- f s 
        let Parser h = g a
        h t

beachte: das return/do gehört zur List-Monade

p :: Parser c (c,c)
p = do x <- next ; y <- next ; return (x,y)



Johannes Waldmann 2011-01-23