Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- class (Alternative m, Monad m) => MonadPlus (m :: * -> *) where
- endBy :: MonadPlus m => m a -> m sep -> m [a]
- endBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a)
- many :: MonadPlus m => m a -> m [a]
- mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a
- sepBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a)
- sepEndBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a)
- someTill :: MonadPlus m => m a -> m end -> m (NonEmpty a)
- manyTill :: MonadPlus m => m a -> m end -> m [a]
- sepBy :: MonadPlus m => m a -> m sep -> m [a]
- sepEndBy :: MonadPlus m => m a -> m sep -> m [a]
- skipMany :: MonadPlus m => m a -> m ()
- skipManyTill :: MonadPlus m => m a -> m end -> m end
- skipSome :: MonadPlus m => m a -> m ()
- skipSomeTill :: MonadPlus m => m a -> m end -> m end
Documentation
class (Alternative m, Monad m) => MonadPlus (m :: * -> *) where #
Monads that also support choice and failure.
The identity of mplus
. It should also satisfy the equations
mzero >>= f = mzero v >> mzero = mzero
The default definition is
mzero = empty
An associative operation. The default definition is
mplus = (<|>
)
Instances
endBy :: MonadPlus m => m a -> m sep -> m [a] #
parses zero or more occurrences of endBy
p sepp
, separated and
ended by sep
. Returns a list of values returned by p
.
cStatements = cStatement `endBy` semicolon
endBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a) #
parses one or more occurrences of endBy1
p sepp
, separated and
ended by sep
. Returns a non-empty list of values returned by p
.
many :: MonadPlus m => m a -> m [a] #
applies the parser many
pp
zero or more times and returns a
list of the values returned by p
.
identifier = (:) <$> letter <*> many (alphaNumChar <|> char '_')
sepBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a) #
parses one or more occurrences of sepBy1
p sepp
, separated by
sep
. Returns a non-empty list of values returned by p
.
sepEndBy1 :: MonadPlus m => m a -> m sep -> m (NonEmpty a) #
parses one or more occurrences of sepEndBy1
p sepp
, separated
and optionally ended by sep
. Returns a non-empty list of values returned by
p
.
someTill :: MonadPlus m => m a -> m end -> m (NonEmpty a) #
works similarly to someTill
p end
, but manyTill
p endp
should succeed at least once.
See also: skipSome
, skipSomeTill
.
manyTill :: MonadPlus m => m a -> m end -> m [a] #
applies parser manyTill
p endp
zero or more times until parser
end
succeeds. Returns the list of values returned by p
.
See also: skipMany
, skipManyTill
.
sepBy :: MonadPlus m => m a -> m sep -> m [a] #
parses zero or more occurrences of sepBy
p sepp
, separated by
sep
. Returns a list of values returned by p
.
commaSep p = p `sepBy` comma
sepEndBy :: MonadPlus m => m a -> m sep -> m [a] #
parses zero or more occurrences of sepEndBy
p sepp
, separated
and optionally ended by sep
. Returns a list of values returned by p
.
skipMany :: MonadPlus m => m a -> m () #
applies the parser skipMany
pp
zero or more times, skipping
its result.
See also: manyTill
, skipManyTill
.
skipManyTill :: MonadPlus m => m a -> m end -> m end #
applies the parser skipManyTill
p endp
zero or more times
skipping results until parser end
succeeds. Result parsed by end
is
then returned.
skipSome :: MonadPlus m => m a -> m () #
applies the parser skipSome
pp
one or more times, skipping its
result.
See also: someTill
, skipSomeTill
.
skipSomeTill :: MonadPlus m => m a -> m end -> m end #
applies the parser skipSomeTill
p endp
one or more times
skipping results until parser end
succeeds. Result parsed by end
is
then returned.