Binding Parser

bindParser

Write a function that accepts a parser and a function from its produced value to another parser producing values of some type and returns a parser producing values of that same type. Again, we will see later why this function is useful.

bindParser :: Parser a -> (a -> Parser b) -> Parser b
bindParser (P p) f = P (\s -> case p s of Just (r, c) -> parse (f c) r
                                          Nothing -> Nothing)