Safe Haskell | Safe |
---|---|
Language | Haskell98 |
ParseLib.Parallel.Core
Synopsis
- data Parser s r
- anySymbol :: Parser s s
- satisfy :: (s -> Bool) -> Parser s s
- empty :: Alternative f => f a
- failp :: Parser s a
- succeed :: a -> Parser s a
- pure :: Applicative f => a -> f a
- (<|>) :: Alternative f => f a -> f a -> f a
- (<<|>) :: Parser s a -> Parser s a -> Parser s a
- (<*>) :: Applicative f => f (a -> b) -> f a -> f b
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- (>>=) :: Monad m => m a -> (a -> m b) -> m b
- look :: Parser s [s]
- parse :: Parser s a -> [s] -> [(a, [s])]
The type of parsers
The parser is a CPS version of Parser'
Elementary parsers
satisfy :: (s -> Bool) -> Parser s s Source #
Takes a predicate and returns a parser that parses a single symbol satisfying that predicate.
empty :: Alternative f => f a #
The identity of <|>
pure :: Applicative f => a -> f a #
Lift a value.
Parser combinators
(<|>) :: Alternative f => f a -> f a -> f a infixl 3 #
An associative binary operation
(<<|>) :: Parser s a -> Parser s a -> Parser s a infixl 3 Source #
Biased choice. Not implemented by the parallel parser combinators. Just maps to parallel choice.
(<*>) :: Applicative f => f (a -> b) -> f a -> f b infixl 4 #
Sequential application.
A few functors support an implementation of <*>
that is more
efficient than the default one.
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #
An infix synonym for fmap
.
The name of this operator is an allusion to $
.
Note the similarities between their types:
($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b
Whereas $
is function application, <$>
is function
application lifted over a Functor
.
Examples
Convert from a
to a Maybe
Int
using Maybe
String
show
:
>>>
show <$> Nothing
Nothing>>>
show <$> Just 3
Just "3"
Convert from an
to an Either
Int
Int
Either
Int
String
using show
:
>>>
show <$> Left 17
Left 17>>>
show <$> Right 17
Right "17"
Double each element of a list:
>>>
(*2) <$> [1,2,3]
[2,4,6]
Apply even
to the second element of a pair:
>>>
even <$> (2,2)
(2,True)
(>>=) :: Monad m => m a -> (a -> m b) -> m b infixl 1 #
Sequentially compose two actions, passing any value produced by the first as an argument to the second.