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 :: forall u a r. Pattern u a (a, a) -> (r -> r -> r) -> Operator u a r
  - AssocR :: forall u a r. Pattern u a (a, a) -> (r -> r -> r) -> Operator u a r
  - Wrap :: forall u a s r. Pattern u a (s, a) -> (s -> r -> r) -> Operator u a r
  - Split :: forall u a s t r. 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

Instances details

Category (Pattern u :: Type -> Type -> Type) # |
Instance details Defined in Control.PatternArrows Methods id :: Pattern u a a # (.) :: Pattern u b c -> Pattern u a b -> Pattern u a c #
Arrow (Pattern u) # |
Instance details Defined in Control.PatternArrows Methods arr :: (b -> c) -> Pattern u b c # first :: Pattern u b c -> Pattern u (b, d) (c, d) # second :: Pattern u b c -> Pattern u (d, b) (d, c) # (***) :: Pattern u b c -> Pattern u b' c' -> Pattern u (b, b') (c, c') # (&&&) :: Pattern u b c -> Pattern u b c' -> Pattern u b (c, c') #
ArrowPlus (Pattern u) # |
Instance details Defined in Control.PatternArrows Methods (<+>) :: Pattern u b c -> Pattern u b c -> Pattern u b c #
ArrowZero (Pattern u) # |
Instance details Defined in Control.PatternArrows Methods zeroArrow :: Pattern u b c #
Functor (Pattern u a) # |
Instance details Defined in Control.PatternArrows Methods fmap :: (a0 -> b) -> Pattern u a a0 -> Pattern u a b # (<$) :: a0 -> Pattern u a b -> Pattern u a a0 #

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 :: forall u a r. Pattern u a (a, a) -> (r -> r -> r) -> Operator u a r |
AssocR :: forall u a r. Pattern u a (a, a) -> (r -> r -> r) -> Operator u a r |
Wrap :: forall u a s r. Pattern u a (s, a) -> (s -> r -> r) -> Operator u a r |
Split :: forall u a s t r. 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