Udo Stenzel wrote:
Stephane Bortzmeyer wrote:
Parsec provides "count n p" to run the parser p exactly n times. I'm
looking for a combinator "countBetween m n p" which will run the
parser between m and n times. It does not exist in Parsec.

infixr 2 <:>
(<:>) = ap . ap (return (:))


Again, Parsec requires you to put "try" where you need it

countBetween 0 0 _ = return []
countBetween 0 n p = try p <:> countBetween   0   (n-1) p <|> return []
countBetween m n p = p <:> countBetween (m-1) (n-1) p

or what I'd ordinarily use:

(<:>) = liftM2 (:)


_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to