proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Tools.HypergraphRewrite.Free

Description

Compile free syntax into typed hypergraphs. Each structure box connects its outer endpoints to the endpoints of its immediate children. Composition shares nodes, and identity is a wire. No interpretation of the structures in the hypergraph category is required. A structure box's inputs are its outer input followed by its child outputs; its outputs are its outer output followed by its child inputs. These connections keep child boundaries distinct from the surrounding composition and expose the children to matching.

freeLawRules compiles laws with object variables and whole-arrow parameters. Object matching uses the reflected free-object grammar, so variables can bind compound objects without adding graph-specific instances of the structures.

Synopsis

Documentation

class CategoryOf k => NamedArrows k where Source Github #

Named generators with arbitrary free-object endpoints, including compound objects. Unlike Emb, these are not restricted to embedded base objects.

Methods

namedArrow :: forall (a :: k) (b :: k). (Ob a, Ob b) => String -> a ~> b Source Github #

Instances

Instances details
Elem NamedArrows cs => NamedArrows (FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Tools.HypergraphRewrite.Free

Methods

namedArrow :: forall (a :: FREE cs p) (b :: FREE cs p). (Ob a, Ob b) => String -> a ~> b Source Github #

data family Struct (c :: Kind -> Constraint) :: CAT (FREE cs p) Source Github #

Instances

Instances details
WithShow a => Show (Struct Monoidal a b) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal

Show (Struct SymMonoidal a b) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal

Show (Struct Cartesian a b) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.Cartesian

WithShow a => Show (Struct Closed a b) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.Closed

Show (Struct CompactClosed a b) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.CompactClosed

WithShow a => Show (Struct Dialogue a b) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.Dialogue

Show (Struct Distributive a b) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.Distributive

Show (Struct IsoMix a b) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.IsoMix

WithShow a => Show (Struct StarAutonomous a b) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.StarAutonomous

WithShow a => Show (Struct HasBinaryCoproducts a b) Source Github # 
Instance details

Defined in Proarrow.Colimit.BinaryCoproduct

Show (Struct HasInitialObject a b) Source Github # 
Instance details

Defined in Proarrow.Colimit.Initial

WithShow a => Show (Struct HasBinaryProducts a b) Source Github # 
Instance details

Defined in Proarrow.Limit.BinaryProduct

Show (Struct HasTerminalObject a b) Source Github # 
Instance details

Defined in Proarrow.Limit.Terminal

Show (Struct Semicartesian a b) Source Github # 
Instance details

Defined in Proarrow.Limit.Terminal

Show (Struct (Supplies Comonoid) a b) Source Github # 
Instance details

Defined in Proarrow.Monoid

Show (Struct (Supplies Monoid) a b) Source Github # 
Instance details

Defined in Proarrow.Monoid

Show (Struct NamedArrows a b) Source Github # 
Instance details

Defined in Proarrow.Tools.HypergraphRewrite.Free

data Struct Monoidal (i :: FREE cs p) (o :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal

data Struct Monoidal (i :: FREE cs p) (o :: FREE cs p) where
data Struct SymMonoidal (i :: FREE cs p) (o :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal

data Struct SymMonoidal (i :: FREE cs p) (o :: FREE cs p) where
data Struct Cartesian (i :: FREE cs p) (o :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.Cartesian

data Struct Cartesian (i :: FREE cs p) (o :: FREE cs p) where
data Struct Closed (a :: FREE cs p) (b :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.Closed

data Struct Closed (a :: FREE cs p) (b :: FREE cs p) where
data Struct CompactClosed (a :: FREE cs p) (b :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.CompactClosed

data Struct CompactClosed (a :: FREE cs p) (b :: FREE cs p) where
data Struct Dialogue (a :: FREE cs p) (b :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.Dialogue

data Struct Dialogue (a :: FREE cs p) (b :: FREE cs p) where
data Struct Distributive (i :: FREE cs p) (o :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.Distributive

data Struct Distributive (i :: FREE cs p) (o :: FREE cs p) where
data Struct IsoMix (a :: FREE cs p) (b :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.IsoMix

data Struct IsoMix (a :: FREE cs p) (b :: FREE cs p) where
data Struct StarAutonomous (a :: FREE cs p) (b :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Category.Monoidal.StarAutonomous

data Struct StarAutonomous (a :: FREE cs p) (b :: FREE cs p) where
data Struct HasBinaryCoproducts (i :: FREE cs p) (o :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Colimit.BinaryCoproduct

data Struct HasBinaryCoproducts (i :: FREE cs p) (o :: FREE cs p) where
data Struct HasInitialObject (a :: FREE cs p) (b :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Colimit.Initial

data Struct HasInitialObject (a :: FREE cs p) (b :: FREE cs p) where
data Struct HasBinaryProducts (i :: FREE cs p) (o :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Limit.BinaryProduct

data Struct HasBinaryProducts (i :: FREE cs p) (o :: FREE cs p) where
data Struct HasTerminalObject (a :: FREE cs p) (b :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Limit.Terminal

data Struct HasTerminalObject (a :: FREE cs p) (b :: FREE cs p) where
data Struct Semicartesian (a :: FREE cs p) (b :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Limit.Terminal

data Struct Semicartesian (a :: FREE cs p) (b :: FREE cs p) where
data Struct NamedArrows (a :: FREE cs p) (b :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Tools.HypergraphRewrite.Free

data Struct NamedArrows (a :: FREE cs p) (b :: FREE cs p) where
data Struct (Supplies Comonoid) (i :: FREE cs p) (o :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Monoid

data Struct (Supplies Comonoid) (i :: FREE cs p) (o :: FREE cs p) where
data Struct (Supplies Monoid) (i :: FREE cs p) (o :: FREE cs p) Source Github # 
Instance details

Defined in Proarrow.Monoid

data Struct (Supplies Monoid) (i :: FREE cs p) (o :: FREE cs p) where

type FREE_OB = SUBCAT (Typeable :: FREE_SHAPE -> Constraint) Source Github #

Discrete sorts for reflected free objects.

type FreeWire (a :: FREE cs p) = Wires '['SUB ('FO (Proxy a)) :: SUBCAT (Typeable :: FREE_SHAPE -> Constraint)] :: OPENHG (SUBCAT (Typeable :: FREE_SHAPE -> Constraint)) l Source Github #

One wire carrying the exact source object, including its syntax category.

data StructureBox (cs :: [Kind -> Constraint]) Source Github #

A structural operation distinguished by its signature's position in cs. Child arrows do not participate in equality; their graph connections do.

Instances

Instances details
Show (StructureBox cs) Source Github # 
Instance details

Defined in Proarrow.Tools.HypergraphRewrite.Free

Eq (StructureBox cs) Source Github # 
Instance details

Defined in Proarrow.Tools.HypergraphRewrite.Free

fromFreeWith :: forall {k} {cs :: [Kind -> Constraint]} {p} l (a :: FREE cs p) (b :: FREE cs p). (Typeable k, Typeable cs, Typeable p, forall (x :: k). Ob x => Typeable x, Discrete k, All cs (FREE cs p), Show2 p, Elem NamedArrows cs) => (forall (x :: k) (y :: k). (Ob x, Ob y) => p x y -> l) -> (String -> l) -> Free a b -> (FreeWire a :: OPENHG FREE_OB (Either (StructureBox cs) l)) ~> (FreeWire b :: OPENHG FREE_OB (Either (StructureBox cs) l)) Source Github #

Compile syntax, mapping base generators and named generators to labels. Host and rule syntax must use the same cs and p, so their reflected wire sorts agree. Named generators can be mapped to parameters when compiling laws. The base is discrete, and all structures must have instances on the source free category.

freeLawRule :: forall (laws :: [Kind -> Constraint]) (cs :: [Kind -> Constraint]) a. (Laws laws, Typeable cs, All cs (ObjectSyntax cs), All laws (ObjectSyntax cs), Elem NamedArrows cs, Eq a) => String -> Either String (Rule FREE_OB (Either (StructureBox cs) a)) Source Github #

Compile a named law with object variables and whole-arrow parameters. One rule handles every instantiation of its five object variables, including compound objects. Repeated variables must have the same object shape. Named arrows capture connected subdiagrams with their own input and output, including anchored identities. Repeated names require boundary-preserving graph isomorphism; substitution does not compare diagrams modulo other laws. Complete matches contain at least one box, and identical replacements are skipped.

freeLawRuleWithDirection :: forall (laws :: [Kind -> Constraint]) (cs :: [Kind -> Constraint]) a. (Laws laws, Typeable cs, All cs (ObjectSyntax cs), All laws (ObjectSyntax cs), Elem NamedArrows cs, Eq a) => String -> Direction -> Either String (Rule FREE_OB (Either (StructureBox cs) a)) Source Github #

Like freeLawRule, with an explicit orientation. Arrow parameters on the right must occur on the left; an unbound right-side object rejects a match.

freeLawRules :: forall (laws :: [Kind -> Constraint]) (cs :: [Kind -> Constraint]) a. (Laws laws, Typeable cs, All cs (ObjectSyntax cs), All laws (ObjectSyntax cs), Elem NamedArrows cs, Eq a) => Either String [(String, Rule FREE_OB (Either (StructureBox cs) a))] Source Github #

Compile all laws with freeLawRule's object and whole-arrow parameters, retaining their names for a shared compileRules.

>>> import Proarrow.Limit.BinaryProduct (HasBinaryProducts)
>>> type ProductStructures = '[NamedArrows, HasBinaryProducts]
>>> fmap (map fst) (freeLawRules @'[HasBinaryProducts] @ProductStructures @String)
Right ["fst","snd","pairing naturality","pairing the projections","pairing uniqueness"]