[Haskell-cafe] Re: [Parsec] A combinator to match between M and N times?

Stephane Bortzmeyer bortzmeyer at nic.fr
Tue Aug 29 09:38:56 EDT 2006


On Tue, Aug 29, 2006 at 03:11:09PM +0200,
 Tomasz Zielonka <tomasz.zielonka at gmail.com> wrote 
 a message of 28 lines which said:

> How about this?

It works fine, many thanks. Here is the version rewritten according to
my taste:

import Text.ParserCombinators.Parsec
import Data.Maybe (catMaybes)

countBetween m n p 
     | n < m     = error "First bound must be lower or equal than second bound"
     | otherwise = do
        xs <- count m p
        ys <- count (n - m) ((option Nothing) (do
            y <- p
            return (Just y)))
        return (xs ++ catMaybes ys)


More information about the Haskell-Cafe mailing list