par is:module

The monad-par package provides a family of Par monads, for speeding up pure computations using parallel processors. (for a similar programming model for use with IO, see Control.Monad.Par.IO.) The result of a given Par computation is always the same - i.e. it is deterministic, but the computation may be performed more quickly if there are processors available to share the work. For example, the following program fragment computes the values of (f x) and (g x) in parallel, and returns a pair of their results:
runPar $ do
fx <- spawnP (f x)  -- start evaluating (f x)
gx <- spawnP (g x)  -- start evaluating (g x)
a  <- get fx        -- wait for fx
b  <- get gx        -- wait for gx
return (a,b)        -- return results
Par can be used for specifying pure parallel computations in which the order of the computation is not known beforehand. The programmer specifies how information flows from one part of the computation to another, but not the order in which computations will be evaluated at runtime. Information flow is described using "variables" called IVars, which support put and get operations. For example, suppose you have a problem that can be expressed as a network with four nodes, where b and c require the value of a, and d requires the value of b and c:
a
/ \               
b   c             
\ /  
d
Then you could express this in the Par monad like this:
runPar $ do
[a,b,c,d] <- sequence [new,new,new,new]
fork $ do x <- get a; put b (x+1)
fork $ do x <- get a; put c (x+2)
fork $ do x <- get b; y <- get c; put d (x+y)
fork $ do put a (3 :: Int)
get d
The result of the above computation is always 9. The get operation waits until its input is available; multiple puts to the same IVar are not allowed, and result in a runtime error. Values stored in IVars are usually fully evaluated (although there are ways provided to pass lazy values if necessary). In the above example, b and c will be evaluated in parallel. In practice the work involved at each node is too small here to see the benefits of parallelism though: typically each node should involve much more work. The granularity is completely under your control - too small and the overhead of the Par monad will outweigh any parallelism benefits, whereas if the nodes are too large then there might not be enough parallelism to use all the available processors. Unlike Control.Parallel, in Control.Monad.Par parallelism is not combined with laziness, so sharing and granularity are completely under the control of the programmer. New units of parallel work are only created by fork and a few other combinators. The default implementation is based on a work-stealing scheduler that divides the work as evenly as possible between the available processors at runtime. Other schedulers are available that are based on different policies and have different performance characteristics. To use one of these other schedulers, just import its module instead of Control.Monad.Par: For more information on the programming model, please see these sources:
This module includes everything you need to get started writing a parser. By default this module is set up to parse character data. If you'd like to parse the result of your own tokenizer you should start with the following imports:
import Text.Parsec.Prim
import Text.Parsec.Combinator
Then you can implement your own version of satisfy on top of the tokenPrim primitive.
Parsec compatibility module
ConstraintKind synonym for marking partial functions
drastically, or be entirely removed, in a future release.
This module provides the generated Happy parser for Haskell. It exports a number of parsers which may be used in any library that uses the GHC API. A common usage pattern is to initialize the parser state with a given string and then parse that string:
runParser :: ParserOpts -> String -> P a -> ParseResult a
runParser opts str parser = unP parser parseState
where
filename = "<interactive>"
location = mkRealSrcLoc (mkFastString filename) 1 1
buffer = stringToStringBuffer str
parseState = initParserState opts buffer location
Parsers for unit/module identifiers
A very simple bytearray parser related to Parsec and Attoparsec Simple example:
> parse ((,,) <$> take 2 <*> byte 0x20 <*> (bytes "abc" *> anyByte)) "xx abctest"
ParseOK "est" ("xx", 116)
Parallel Constructs
Some helpers for parsing data out of a raw WAI Request.
Annotated parser for Haskell with extensions.
This module provides both a native Haskell solution for parsing XML documents into a stream of events, and a set of parser combinators for dealing with a stream of events. As a simple example:
>>> :set -XOverloadedStrings

>>> import Conduit (runConduit, (.|))

>>> import Data.Text (Text, unpack)

>>> import Data.XML.Types (Event)

>>> data Person = Person Int Text Text deriving Show

>>> :{
let parsePerson :: MonadThrow m => ConduitT Event o m (Maybe Person)
parsePerson = tag' "person" parseAttributes $ \(age, goodAtHaskell) -> do
name <- content
return $ Person (read $ unpack age) name goodAtHaskell
where parseAttributes = (,) <$> requireAttr "age" <*> requireAttr "goodAtHaskell" <* ignoreAttrs
parsePeople :: MonadThrow m => ConduitT Event o m (Maybe [Person])
parsePeople = tagNoAttr "people" $ many parsePerson
inputXml = mconcat
[ "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
, "<people>"
, "  <person age=\"25\" goodAtHaskell=\"yes\">Michael</person>"
, "  <person age=\"2\" goodAtHaskell=\"might become\">Eliezer</person>"
, "</people>"
]
:}
>>> runConduit $ parseLBS def inputXml .| force "people required" parsePeople
[Person 25 "Michael" "yes",Person 2 "Eliezer" "might become"]
This module also supports streaming results using yield. This allows parser results to be processed using conduits while a particular parser (e.g. many) is still running. Without using streaming results, you have to wait until the parser finished before you can process the result list. Large XML files might be easier to process by using streaming results. See http://stackoverflow.com/q/21367423/2597135 for a related discussion.
>>> import Data.Conduit.List as CL

>>> :{
let parsePeople' :: MonadThrow m => ConduitT Event Person m (Maybe ())
parsePeople' = tagNoAttr "people" $ manyYield parsePerson
:}
>>> runConduit $ parseLBS def inputXml .| force "people required" parsePeople' .| CL.mapM_ print
Person 25 "Michael" "yes"
Person 2 "Eliezer" "might become"
Previous versions of this module contained a number of more sophisticated functions written by Aristid Breitkreuz and Dmitry Olshansky. To keep this package simpler, those functions are being moved to a separate package. This note will be updated with the name of the package(s) when available.
A CSV parser. The parser defined here is RFC 4180 compliant, with the following extensions:
  • Empty lines are ignored.
  • Non-escaped fields may contain any characters except double-quotes, commas, carriage returns, and newlines.
  • Escaped fields may contain any characters (but double-quotes need to be escaped).
The functions in this module can be used to implement e.g. a resumable parser that is fed input incrementally.
This module corresponds to section 3.8.4 (Texture Parameters), section 3.8.7 (Texture Wrap Mode), section 3.8.8 (Texture Minification), and section 3.8.9 (Texture Magnification) of the OpenGL 2.1 specs.
A utility library with parsers used in pandoc readers.
interface to the HXT XML and DTD parsers