
From the source of the package Text.ParserCombinators.ReadP, available at http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Text-Pa... :
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. /Fredrik

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-Pa... :
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
participants (2)
-
Christian Maeder
-
Obscaenvs 74