HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulepipes-parse-3.0.9Haskell2010

Pipes.Parse

Element-agnostic parsing utilities for pipes

See Pipes.Parse.Tutorial for an extended tutorial

  • 3 types
  • 23 values
  • Packagepipes-parse-3.0.9
  • Exports27
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceParse.hs

Parsing

10 declarations

pipes-parse handles end-of-input and pushback by storing a Producer in a StateT layer.

Connect Parsers to Producers using either runStateT, evalStateT, or execStateT:

runStateT  :: Parser a m r -> Producer a m x -> m (r, Producer a m x)
evalStateT :: Parser a m r -> Producer a m x -> m  r
execStateT :: Parser a m r -> Producer a m x -> m    (Producer a m x)
                                                      ^^^^^^^^^^^^^^
                                                         Leftovers
valuedrawAll :: Monad m => Parser a m [a]
#

Draw all elements from the underlying Producer

Note that drawAll is not an idiomatic use of pipes-parse, but I provide it for simple testing purposes. Idiomatic pipes-parse style consumes the elements immediately as they are generated instead of loading all elements into memory. For example, you can use foldAll or foldAllM for this purpose.

valuepeek :: Monad m => Parser a m (Maybe a)
#

peek checks the first element of the stream, but uses unDraw to push the element back so that it is available for the next draw command.

peek = do
    x <- draw
    case x of
        Nothing -> return ()
        Just a  -> unDraw a
    return x
valuefoldAll
  1. :: Monad m
  2. => (x -> a -> x)

    Step function

  3. -> x

    Initial accumulator

  4. -> (x -> b)

    Extraction function

  5. -> Parser a m b
#

Fold all input values

Control.Foldl.purely foldAll :: Monad m => Fold a b -> Parser a m b
valuefoldAllM
  1. :: Monad m
  2. => (x -> a -> m x)

    Step function

  3. -> m x

    Initial accumulator

  4. -> (x -> m b)

    Extraction function

  5. -> Parser a m b
#

Fold all input values monadically

Control.Foldl.impurely foldAllM :: Monad m => FoldM a m b -> Parser a m b

Parsing Lenses

4 declarations

Connect lenses to Producers using (^.) or view:

(^.) :: Producer a m x
     -> Lens' (Producer a m x) (Producer b m y)
     -> Producer b m y

Connect lenses to Parsers using zoom:

zoom :: Lens' (Producer a m x) (Producer b m y)
     -> Parser b m r
     -> Parser a m r

Connect lenses to each other using (.) (i.e. function composition):

(.) :: Lens' (Producer a m x) (Producer b m y)
    -> Lens' (Producer b m y) (Producer c m z)
    -> Lens' (Producer a m y) (Producer c m z)

Utilities

6 declarations

Re-exports

7 declarations
methodlift :: Monad m => m a -> t m a
#

Lift a computation from the argument monad to the constructed monad.

newtypenewtype StateT s (m :: Type -> Type) a
#

A state transformer monad parameterized by:

  • s - The state.

  • m - The inner monad.

The return function leaves the state unchanged, while >>= uses the final state of the first computation as the initial state of the second.

Constructors

Instances23MFunctor, MonadAccum, MonadError, MonadReader, MonadState, MonadWriter, …