proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Tools.HypergraphRewrite.Laws

Description

Instantiate named categorical laws as hypergraph rewrite rules.

Synopsis

Documentation

data Direction Source Github #

Orient an equation as written in its Law body, or in reverse.

Constructors

LeftToRight 
RightToLeft 

ruleWith :: forall (cs :: [Kind -> Constraint]) s l. Laws cs => String -> (LawBody cs -> Equation (OPENHG s l)) -> Either String (Rule s l) Source Github #

Select a law left-to-right, using an explicit interpretation to choose its object variables, supplied arrows, and representation of the structures. Unknown and ambiguous law names are errors. The interpreted equation must satisfy rule's restriction on the oriented left boundary.

The interpretation receives the polymorphic body. Instantiate it in a diagram category supporting the requested structures, then use withSides to lower both sides to parallel open hypergraphs. Supplied arrows are concrete; this does not introduce variables matching arbitrary subdiagrams.

ruleWithDirection :: forall (cs :: [Kind -> Constraint]) s l. Laws cs => String -> Direction -> (LawBody cs -> Equation (OPENHG s l)) -> Either String (Rule s l) Source Github #

Like ruleWith, with an explicit choice of direction.

parameterRuleWith :: forall (cs :: [Kind -> Constraint]) s f a. (Laws cs, Traversable f, Eq (f ()), Typeable f, Eq a) => String -> (LawBody cs -> Equation (OPENHG s (f (Parameter a)))) -> Either String (Rule s (f a)) Source Github #

Select a law left-to-right with the label parameters of parameterRule. The interpretation supplies named arrows as boxes labelled with Variable, and structural operations as fixed constructors or Literal fields. Repeated names must bind equal values; the right side reuses those bindings. Object choices and box arities remain fixed, and variables do not match subdiagrams. Compile once, then apply with rewrites or include in compileRules.

parameterRuleWithDirection :: forall (cs :: [Kind -> Constraint]) s f a. (Laws cs, Traversable f, Eq (f ()), Typeable f, Eq a) => String -> Direction -> (LawBody cs -> Equation (OPENHG s (f (Parameter a)))) -> Either String (Rule s (f a)) Source Github #

Like parameterRuleWith, with an explicit choice of direction. Parameters on the oriented right side must be bound on the oriented left side.

parameterRulesWith :: forall (cs :: [Kind -> Constraint]) s f a. (Laws cs, Traversable f, Eq (f ()), Typeable f, Eq a) => (LawBody cs -> Equation (OPENHG s (f (Parameter a)))) -> Either String [(String, Rule s (f a))] Source Github #

Instantiate every law left-to-right with parameterRuleWith, retaining its name for compileRules. Duplicate law names and invalid rules are errors.

subgraphRuleWithDirection :: forall (cs :: [Kind -> Constraint]) s p l. Laws cs => String -> Direction -> (p -> Either l String) -> (LawBody cs -> Equation (OPENHG s p)) -> Either String (Rule s l) Source Github #

Select a law with the whole-arrow parameters of subgraphRule.

rewritesWith :: forall (cs :: [Kind -> Constraint]) s l (a :: OPENHG s l) (b :: OPENHG s l). (Laws cs, Eq l, DecidableIso s) => String -> (LawBody cs -> Equation (OPENHG s l)) -> (a ~> b) -> Either String [(Wires (WireSorts a) :: OPENHG s l) ~> (Wires (WireSorts b) :: OPENHG s l)] Source Github #

Select an explicitly instantiated law left-to-right and enumerate its single-step rewrites. Compile once with ruleWith when applying the same instantiation to several hosts.

rewritesWithDirection :: forall (cs :: [Kind -> Constraint]) s l (a :: OPENHG s l) (b :: OPENHG s l). (Laws cs, Eq l, DecidableIso s) => String -> Direction -> (LawBody cs -> Equation (OPENHG s l)) -> (a ~> b) -> Either String [(Wires (WireSorts a) :: OPENHG s l) ~> (Wires (WireSorts b) :: OPENHG s l)] Source Github #

Like rewritesWith, with an explicit choice of direction.