-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Arrows for Pretty Printing
--   
--   A library for generating concise pretty printers based on precedence
--   rules.
@package pattern-arrows
@version 0.0.2


-- | Arrows for Pretty Printing
module Control.PatternArrows

-- | A first-order pattern match
--   
--   A pattern is a Kleisli arrow for the <tt>StateT Maybe</tt> monad. That
--   is, patterns can fail, and can carry user-defined state.
newtype Pattern u a b
Pattern :: Kleisli (StateT u Maybe) a b -> Pattern u a b
[runPattern] :: Pattern u a b -> Kleisli (StateT u Maybe) a b

-- | Run a pattern with an input and initial user state
--   
--   Returns Nothing if the pattern fails to match
pattern :: Pattern u a b -> u -> a -> Maybe b

-- | Construct a pattern from a function
mkPattern :: (a -> Maybe b) -> Pattern u a b

-- | Construct a pattern from a stateful function
mkPattern' :: (a -> StateT u Maybe b) -> Pattern u a b

-- | Construct a pattern which recursively matches on the left-hand-side
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 right-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 one-side of a tuple
wrap :: Pattern u a (s, a) -> (s -> r -> r) -> Pattern u a r -> Pattern u a r

-- | Construct a pattern which matches a part of a tuple
split :: Pattern u a (s, t) -> (s -> t -> r) -> Pattern u a r

-- | A table of operators
data OperatorTable u a r
OperatorTable :: [[Operator u a r]] -> OperatorTable u a r
[runOperatorTable] :: OperatorTable u a r -> [[Operator u a r]]

-- | An operator:
--   
--   <ul>
--   <li><i><tt>AssocL</tt></i> A left-associative operator</li>
--   <li><i><tt>AssocR</tt></i> A right-associative operator</li>
--   <li><i><tt>Wrap</tt></i> A prefix-like or postfix-like operator</li>
--   <li><i><tt>Split</tt></i> A prefix-like or postfix-like operator which
--   does not recurse into its operand</li>
--   </ul>
data Operator u a r
[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

-- | Build a pretty printer from an operator table and an indecomposable
--   pattern
buildPrettyPrinter :: OperatorTable u a r -> Pattern u a r -> Pattern u a r
instance Control.Arrow.ArrowPlus (Control.PatternArrows.Pattern u)
instance Control.Arrow.ArrowZero (Control.PatternArrows.Pattern u)
instance Control.Arrow.Arrow (Control.PatternArrows.Pattern u)
instance Control.Category.Category (Control.PatternArrows.Pattern u)
instance GHC.Base.Functor (Control.PatternArrows.Pattern u a)
