Control.PatternArrows

pattern-arrows-0.0.2: Arrows for Pretty Printing

Safe Haskell | None
Language | Haskell98

Control.PatternArrows

Description

Arrows for Pretty Printing

Synopsis

- newtype Pattern u a b = Pattern {
  - runPattern :: Kleisli (StateT u Maybe) a b
  }
- pattern :: Pattern u a b -> u -> a -> Maybe b
- mkPattern :: (a -> Maybe b) -> Pattern u a b
- mkPattern' :: (a -> StateT u Maybe b) -> Pattern u a b
- chainl :: Pattern u a (a, a) -> (r -> r -> r) -> Pattern u a r -> Pattern u a r
- chainr :: Pattern u a (a, a) -> (r -> r -> r) -> Pattern u a r -> Pattern u a r
- wrap :: Pattern u a (s, a) -> (s -> r -> r) -> Pattern u a r -> Pattern u a r
- split :: Pattern u a (s, t) -> (s -> t -> r) -> Pattern u a r
- data OperatorTable u a r = OperatorTable {
  - runOperatorTable :: [[Operator u a r]]
  }
- data Operator u a r where
  - AssocL :: Pattern u a (a, a) -> (r -> r -> r) -> Operator u a r
  - AssocR :: Pattern u a (a, a) -> (r -> r -> r) -> Operator u a r
  - Wrap :: Pattern u a (s, a) -> (s -> r -> r) -> Operator u a r
  - Split :: Pattern u a (s, t) -> (s -> t -> r) -> Operator u a r
- buildPrettyPrinter :: OperatorTable u a r -> Pattern u a r -> Pattern u a r

# Documentation

newtype Pattern u a b

A first-order pattern match

A pattern is a Kleisli arrow for the `StateT Maybe` monad. That is, patterns can fail, and can carry user-defined state.

Constructors

Pattern |
Fields runPattern :: Kleisli (StateT u Maybe) a b

Instances

Category * (Pattern u) |
Arrow (Pattern u) |
ArrowZero (Pattern u) |
ArrowPlus (Pattern u) |
Functor (Pattern u a) |

pattern :: Pattern u a b -> u -> a -> Maybe b

Run a pattern with an input and initial user state

Returns Nothing if the pattern fails to match

mkPattern :: (a -> Maybe b) -> Pattern u a b

Construct a pattern from a function

mkPattern' :: (a -> StateT u Maybe b) -> Pattern u a b

Construct a pattern from a stateful function

chainl :: Pattern u a (a, a) -> (r -> r -> r) -> Pattern u a r -> Pattern u a r

Construct a pattern which recursively matches on the left-hand-side

chainr :: Pattern u a (a, a) -> (r -> r -> r) -> Pattern u a r -> Pattern u a r

Construct a pattern which recursively matches on the right-hand side

wrap :: Pattern u a (s, a) -> (s -> r -> r) -> Pattern u a r -> Pattern u a r

Construct a pattern which recursively matches on one-side of a tuple

split :: Pattern u a (s, t) -> (s -> t -> r) -> Pattern u a r

Construct a pattern which matches a part of a tuple

data OperatorTable u a r

A table of operators

Constructors

OperatorTable |
Fields runOperatorTable :: [[Operator u a r]]

data Operator u a r where

An operator:

`AssocL`
  A left-associative operator
`AssocR`
  A right-associative operator
`Wrap`
  A prefix-like or postfix-like operator
`Split`
  A prefix-like or postfix-like operator which does not recurse into its operand

Constructors

AssocL :: Pattern u a (a, a) -> (r -> r -> r) -> Operator u a r |
AssocR :: Pattern u a (a, a) -> (r -> r -> r) -> Operator u a r |
Wrap :: Pattern u a (s, a) -> (s -> r -> r) -> Operator u a r |
Split :: Pattern u a (s, t) -> (s -> t -> r) -> Operator u a r |

buildPrettyPrinter :: OperatorTable u a r -> Pattern u a r -> Pattern u a r

Build a pretty printer from an operator table and an indecomposable pattern