[Haskell-beginners] Impossible lib definition?

Christian Maeder Christian.Maeder at dfki.de
Mon Jul 18 15:55:55 CEST 2011


Am 18.07.2011 10:27, schrieb Obscaenvs 74:
>  From the source of the package Text.ParserCombinators.ReadP, available
> at http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Text-ParserCombinators-ReadP.html#many
> :
>
> many :: ReadP a ->  ReadP [a]
> -- ^ Parses zero or more occurrences of the given parser.
> many p = return [] +++ many1 p
>
> many1 :: ReadP a ->  ReadP [a]
> -- ^ Parses one or more occurrences of the given parser.
> many1 p = liftM2 (:) p (many p)
>
>
> So  `many` is defined in terms of `many1` and vice versa - completely
> understandable, but here the argument (`p`) does not change. This is
> above me right now. Anyone care to explain? I'd be grateful. Not that
> I have to understand it, but it keeps pestering me during my lonely
> hours.

"p" is a common (non-changing) argument for parsing exactly one occurrence.

The termination is controlled by the choice operator +++ or the length 
of the input string, provided the argument "p" does consume at least one 
character from the input.

HTH Christian

>
> /Fredrik
>



More information about the Beginners mailing list