HORIZON HASKELLDocslts/ghc-10.0.xfc4e5982026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · fc4e598 · 2026-10-11

Moduleappar-0.1.8Haskell98

Text.Appar.LazyByteString

Simple Applicative parser whose input is lazy ByteString. The usage is the same as parsec.

Parsec 3 provides features which Parsec 2 does not provide:

But Haskell Platform includes Parsec 2, not Parsec 3. Installing Parsec 3 to Haskell Platform environment makes it mess. So, this library was implemented.

  • 2 types
  • 1 class
  • 20 values
  • Packageappar-0.1.8
  • Exports31
  • LanguageHaskell98
  • LicenceBSD-3-Clause
  • SourceLazyByteString.hs

Documentation

0 declarations

Parser type

valuealphaNum :: Input inp => MkParser inp Char
#

Parses a letter or digit (a character between '0' and '9'). Returns the parsed character.

valuechoice :: [MkParser inp a] -> MkParser inp a
#

choice ps tries to apply the parsers in the list ps in order, until one of them succeeds. Returns the value of the succeeding parser.

valuehexDigit :: Input inp => MkParser inp Char
#

Parses a hexadecimal digit (a digit or a letter between 'a' and 'f' or 'A' and 'F'). Returns the parsed character.

valuemanyTill :: MkParser inp a -> MkParser inp b -> MkParser inp [a]
#

manyTill p end applies parser p zero or more times until parser end succeeds. Returns the list of values returned by p.

valuenoneOf :: Input inp => String -> MkParser inp Char
#

As the dual of oneOf, noneOf cs succeeds if the current character not in the supplied list of characters cs. Returns the parsed character.

valueoneOf :: Input inp => String -> MkParser inp Char
#

oneOf cs succeeds if the current character is in the supplied list of characters cs. Returns the parsed character.

valueoption :: a -> MkParser inp a -> MkParser inp a
#

option x p tries to apply parser p. If p fails without consuming input, it returns the value x, otherwise the value returned by p.

valuesatisfy :: Input inp => (Char -> Bool) -> MkParser inp Char
#

The parser satisfy f succeeds for any character for which the supplied function f returns True. Returns the character that is actually parsed.

valuesepBy1 :: MkParser inp a -> MkParser inp b -> MkParser inp [a]
#

sepBy1 p sep parses one or more occurrences of p, separated by sep. Returns a list of values returned by p.

valueskipMany :: MkParser inp a -> MkParser inp ()
#

skipMany p applies the parser p zero or more times, skipping its result.

valueskipSome :: MkParser inp a -> MkParser inp ()
#

skipSome p applies the parser p one or more times, skipping its result.

valuespace :: Input inp => MkParser inp Char
#

Parses a white space character (any character which satisfies isSpace) Returns the parsed character.

valuetry :: MkParser inp a -> MkParser inp a
#

The parser try p behaves like parser p, except that it pretends that it hasn't consumed any input when an error occurs.

value(<**>) :: Applicative f => f a -> f (a -> b) -> f b
#

A variant of <*> with the types of the arguments reversed. It differs from flip (<*>) in that the effects are resolved in the order the arguments are presented.

Examples
Example1 expression
(<**>) (print 1) (id <$ print 2)12
Example1 expression
flip (<*>) (print 1) (id <$ print 2)21
Example1 expression
ZipList [4, 5, 6] <**> ZipList [(+1), (*2), (/3)]ZipList {getZipList = [5.0,10.0,2.0]}
value(<$>) :: Functor f => (a -> b) -> f a -> f b
#

An infix synonym for fmap.

The name of this operator is an allusion to Prelude.$. Note the similarities between their types:

 ($)  ::              (a -> b) ->   a ->   b
(<$>) :: Functor f => (a -> b) -> f a -> f b

Whereas Prelude.$ is function application, <$> is function application lifted over a Functor.

Examples

Convert from a Maybe Int to a Maybe String using show:

Example1 expression
show <$> NothingNothing
Example1 expression
show <$> Just 3Just "3"

Convert from an Either Int Int to an Either Int String using show:

Example1 expression
show <$> Left 17Left 17
Example1 expression
show <$> Right 17Right "17"

Double each element of a list:

Example1 expression
(*2) <$> [1,2,3][2,4,6]

Apply even to the second element of a pair:

Example1 expression
even <$> (2,2)(2,True)
classclass Eq inp => Input inp where
#

The class for parser input.

Methods

  • car :: inp -> Char

    The head function for input

  • cdr :: inp -> inp

    The tail function for input

  • nil :: inp

    The end of input

  • isNil :: inp -> Bool

    The function to check the end of input

Instances3Input
datadata MkParser inp a
#

Constructors

Instances6Monad, Functor, MonadFail, Applicative, Alternative, MonadPlus
method(<|>) :: f a -> f a -> f a
#

An associative binary operation

methodmany :: f a -> f [a]
#

Zero or more.

Examples
Example1 expression
many (putStr "la")lalalalalalalalala... * goes on forever *
Example1 expression
many NothingJust []
Example1 expression
take 5 <$> many (Just 1)* hangs forever *

Note that this function can be used with Parsers based on Applicatives. In that case many parser will attempt to parse parser zero or more times until it fails.

methodsome :: f a -> f [a]
#

One or more.

Examples
Example1 expression
some (putStr "la")lalalalalalalalala... * goes on forever *
Example1 expression
some Nothingnothing
Example1 expression
take 5 <$> some (Just 1)* hangs forever *

Note that this function can be used with Parsers based on Applicatives. In that case some parser will attempt to parse parser one or more times until it fails.

method(*>) :: f a -> f b -> f b
#

Sequence actions, discarding the value of the first argument.

Examples

If used in conjunction with the Applicative instance for Maybe, you can chain Maybe computations, with a possible "early return" in case of Nothing.

Example1 expression
Just 2 *> Just 3Just 3
Example1 expression
Nothing *> Just 3Nothing

Of course a more interesting use case would be to have effectful computations instead of just returning pure values.

Example4 expressions
import Data.Charimport GHC.Internal.Text.ParserCombinators.ReadPlet p = string "my name is " *> munch1 isAlpha <* eofreadP_to_S p "my name is Simon"[("Simon","")]
method(<*) :: f a -> f b -> f a
#

Sequence actions, discarding the value of the second argument.

method(<*>) :: f (a -> b) -> f a -> f b
#

Sequential application.

A few functors support an implementation of <*> that is more efficient than the default one.

Example

Used in combination with (Data.Functor.<$>), (<*>) can be used to build a record.

Example1 expression
data MyState = MyState {arg1 :: Foo, arg2 :: Bar, arg3 :: Baz}
Example3 expressions
produceFoo :: Applicative f => f FooproduceBar :: Applicative f => f BarproduceBaz :: Applicative f => f Baz
Example2 expressions
mkState :: Applicative f => f MyStatemkState = MyState <$> produceFoo <*> produceBar <*> produceBaz
methodpure :: a -> f a
#

Lift a value into the Structure.

Examples
Example1 expression
pure 1 :: Maybe IntJust 1
Example1 expression
pure 'z' :: [Char]"z"
Example1 expression
pure (pure ":D") :: Maybe [String]Just [":D"]
method(<$) :: a -> f b -> f a
#

Replace all locations in the input with the same value. The default definition is fmap . const, but this may be overridden with a more efficient version.

Examples

Perform a computation with Maybe and replace the result with a constant value if it is Just:

Example2 expressions
'a' <$ Just 2Just 'a''a' <$ NothingNothing