proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Tools.SMC.Internal.Context

Description

Internal module of Proarrow.Tools.SMC: the contexts of terms, and the operations on them that reorder, copy and discard variables. It exports everything, also what the public module keeps hidden.

Synopsis

Documentation

type Ctx k = [(Nat, SYN k)] Source Github #

A context: the variables a term uses, each with its id and type, by descending id.

type family Mul (g :: Ctx k) :: SYN k where ... Source Github #

The type standing in for a context: the tensor of its variables' types, with the most recently bound variable on the right. A single variable is just its type, so a variable is the identity. The cost is that Mul ('(n, a) ': g) only reduces once g is known to be empty or not, which ctxCase tells.

Equations

Mul ('[] :: [(Nat, SYN k)]) = 'I :: SYN k 
Mul ('['(n, a)] :: [(Nat, SYN k)]) = a 
Mul ('(n, a) ': g :: [(Nat, SYN k)]) = Mul g ':** a 

class KnownCtx (g :: Ctx k) where Source Github #

A context that is known to be empty or not, all the way down.

Methods

ctxCase :: (g ~ ('[] :: [(Nat, SYN k)]) => r) -> (forall (n :: Nat) (a :: SYN k) (g' :: [(Nat, SYN k)]). (g ~ ('(n, a) ': g'), KnownObj a, KnownCtx g') => r) -> r Source Github #

Case analysis on the context, which is what lets Mul ('(n, a) ': g) reduce.

withCtxOb :: Monoidal k => (Ob (Interp (Mul g)) => r) -> r Source Github #

The tensor of a context is an object. A method rather than a function over ctxCase, so that at a known context it is not recursive and can be inlined.

Instances

Instances details
KnownCtx ('[] :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

ctxCase :: (('[] :: [(Nat, SYN k)]) ~ ('[] :: [(Nat, SYN k)]) => r) -> (forall (n :: Nat) (a :: SYN k) (g' :: [(Nat, SYN k)]). (('[] :: [(Nat, SYN k)]) ~ ('(n, a) ': g'), KnownObj a, KnownCtx g') => r) -> r Source Github #

withCtxOb :: Monoidal k => (Ob (Interp (Mul ('[] :: [(Nat, SYN k)]))) => r) -> r Source Github #

(KnownObj a, KnownCtx g) => KnownCtx ('(n, a) ': g :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

ctxCase :: (('(n, a) ': g) ~ ('[] :: [(Nat, SYN k)]) => r) -> (forall (n0 :: Nat) (a0 :: SYN k) (g' :: [(Nat, SYN k)]). (('(n, a) ': g) ~ ('(n0, a0) ': g'), KnownObj a0, KnownCtx g') => r) -> r Source Github #

withCtxOb :: Monoidal k => (Ob (Interp (Mul ('(n, a) ': g))) => r) -> r Source Github #

ctxOb :: forall {k} (g :: Ctx k). (Monoidal k, KnownCtx g) => Obj (Interp (Mul g)) Source Github #

The identity on the tensor of a context.

snoc :: forall {k} (n :: Nat) (a :: SYN k) (g :: Ctx k). (Monoidal k, KnownObj a, KnownCtx g) => (Interp (Mul g) ** Interp a) ~> Interp (Mul ('(n, a) ': g)) Source Github #

A new variable on the right of a context: a unitor if the context was empty, and nothing otherwise.

type family Union (g1 :: Ctx k) (g2 :: Ctx k) :: Ctx k where ... Source Github #

The context of two terms used side by side.

Equations

Union ('[] :: [(Nat, SYN k)]) (g2 :: Ctx k) = g2 
Union (g1 :: Ctx k) ('[] :: [(Nat, SYN k)]) = g1 
Union ('(n, a) ': g1 :: [(Nat, SYN k)]) ('(m, b) ': g2 :: [(Nat, SYN k)]) = UnionBy (CmpNat n m) ('(n, a) ': g1) ('(m, b) ': g2) 

type family UnionBy (o :: Ordering) (g1 :: Ctx k) (g2 :: Ctx k) :: Ctx k where ... Source Github #

Equations

UnionBy 'GT (x ': g1 :: [(Nat, SYN k)]) (g2 :: Ctx k) = x ': Union g1 g2 
UnionBy 'LT (g1 :: Ctx k) (y ': g2 :: [(Nat, SYN k)]) = y ': Union g1 g2 
UnionBy 'EQ (x ': g1 :: [(Nat, SYN k)]) (y ': g2 :: [(Nat, SYN k)]) = x ': Union g1 g2 

unsnoc :: forall {k} (n :: Nat) (a :: SYN k) (g :: Ctx k). (Monoidal k, KnownObj a, KnownCtx g) => Interp (Mul ('(n, a) ': g)) ~> (Interp (Mul g) ** Interp a) Source Github #

The newest variable split off the tensor of a context, the inverse of snoc.

class (KnownCtx g1, KnownCtx g2) => Merge (g1 :: Ctx k) (g2 :: Ctx k) where Source Github #

Split the tensor of the union of two contexts into the tensors of the two contexts. This is where the wires are reordered, the only place swap is used, and where a variable that both contexts have is copied.

Methods

merge :: Interp (Mul (Union g1 g2)) ~> (Interp (Mul g1) ** Interp (Mul g2)) Source Github #

Instances

Instances details
(Monoidal k, KnownCtx g2) => Merge ('[] :: [(Nat, SYN k)]) (g2 :: Ctx k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

merge :: Interp (Mul (Union ('[] :: [(Nat, SYN k)]) g2)) ~> (Interp (Mul ('[] :: [(Nat, SYN k)])) ** Interp (Mul g2)) Source Github #

(Monoidal k, KnownCtx ('(n, a) ': g1)) => Merge ('(n, a) ': g1 :: [(Nat, SYN k)]) ('[] :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

merge :: Interp (Mul (Union ('(n, a) ': g1) ('[] :: [(Nat, SYN k)]))) ~> (Interp (Mul ('(n, a) ': g1)) ** Interp (Mul ('[] :: [(Nat, SYN k)]))) Source Github #

(Monoidal k, KnownObj a, KnownObj b, KnownCtx g1, KnownCtx g2, MergeBy (CmpNat n m) ('(n, a) ': g1) ('(m, b) ': g2)) => Merge ('(n, a) ': g1 :: [(Natural, SYN k)]) ('(m, b) ': g2 :: [(Natural, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

merge :: Interp (Mul (Union ('(n, a) ': g1) ('(m, b) ': g2))) ~> (Interp (Mul ('(n, a) ': g1)) ** Interp (Mul ('(m, b) ': g2))) Source Github #

class (KnownCtx g1, KnownCtx g2) => MergeBy (o :: Ordering) (g1 :: Ctx k) (g2 :: Ctx k) where Source Github #

merge for two non-empty contexts, by which of the two has the larger head id.

Methods

mergeBy :: Interp (Mul (UnionBy o g1 g2)) ~> (Interp (Mul g1) ** Interp (Mul g2)) Source Github #

Instances

Instances details
(SymMonoidal k, CocommutativeComonoid (Interp a), KnownObj a, a ~ b, Merge g1 g2, KnownCtx (Union g1 g2)) => MergeBy 'EQ ('(n, a) ': g1 :: [(Nat, SYN k)]) ('(m, b) ': g2 :: [(Nat, SYN k)]) Source Github #

A variable both contexts have is copied, one copy for each side.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

mergeBy :: Interp (Mul (UnionBy 'EQ ('(n, a) ': g1) ('(m, b) ': g2))) ~> (Interp (Mul ('(n, a) ': g1)) ** Interp (Mul ('(m, b) ': g2))) Source Github #

(SymMonoidal k, Merge g1 ('(m, b) ': g2), KnownObj a, KnownObj b, Mul ('(n, a) ': Union g1 ('(m, b) ': g2)) ~ (Mul (Union g1 ('(m, b) ': g2)) ':** a)) => MergeBy 'GT ('(n, a) ': g1 :: [(Nat, SYN k)]) ('(m, b) ': g2 :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

mergeBy :: Interp (Mul (UnionBy 'GT ('(n, a) ': g1) ('(m, b) ': g2))) ~> (Interp (Mul ('(n, a) ': g1)) ** Interp (Mul ('(m, b) ': g2))) Source Github #

(Monoidal k, Merge ('(n, a) ': g1) g2, KnownObj a, KnownObj b, Mul ('(m, b) ': Union ('(n, a) ': g1) g2) ~ (Mul (Union ('(n, a) ': g1) g2) ':** b)) => MergeBy 'LT ('(n, a) ': g1 :: [(Nat, SYN k)]) ('(m, b) ': g2 :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

mergeBy :: Interp (Mul (UnionBy 'LT ('(n, a) ': g1) ('(m, b) ': g2))) ~> (Interp (Mul ('(n, a) ': g1)) ** Interp (Mul ('(m, b) ': g2))) Source Github #

class (KnownCtx g1, KnownCtx g2) => Unmerge (g1 :: Ctx k) (g2 :: Ctx k) where Source Github #

The inverse of merge for two contexts without a variable in common, which a rec block uses to put the wires it feeds back together with the others.

Methods

unmerge :: (Interp (Mul g1) ** Interp (Mul g2)) ~> Interp (Mul (Union g1 g2)) Source Github #

Instances

Instances details
(Monoidal k, KnownCtx g2) => Unmerge ('[] :: [(Nat, SYN k)]) (g2 :: Ctx k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

unmerge :: (Interp (Mul ('[] :: [(Nat, SYN k)])) ** Interp (Mul g2)) ~> Interp (Mul (Union ('[] :: [(Nat, SYN k)]) g2)) Source Github #

(Monoidal k, KnownCtx ('(n, a) ': g1)) => Unmerge ('(n, a) ': g1 :: [(Nat, SYN k)]) ('[] :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

unmerge :: (Interp (Mul ('(n, a) ': g1)) ** Interp (Mul ('[] :: [(Nat, SYN k)]))) ~> Interp (Mul (Union ('(n, a) ': g1) ('[] :: [(Nat, SYN k)]))) Source Github #

(Monoidal k, KnownObj a, KnownObj b, KnownCtx g1, KnownCtx g2, UnmergeBy (CmpNat n m) ('(n, a) ': g1) ('(m, b) ': g2)) => Unmerge ('(n, a) ': g1 :: [(Natural, SYN k)]) ('(m, b) ': g2 :: [(Natural, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

unmerge :: (Interp (Mul ('(n, a) ': g1)) ** Interp (Mul ('(m, b) ': g2))) ~> Interp (Mul (Union ('(n, a) ': g1) ('(m, b) ': g2))) Source Github #

class (KnownCtx g1, KnownCtx g2) => UnmergeBy (o :: Ordering) (g1 :: Ctx k) (g2 :: Ctx k) where Source Github #

unmerge for two non-empty contexts, by which of the two has the larger head id.

Methods

unmergeBy :: (Interp (Mul g1) ** Interp (Mul g2)) ~> Interp (Mul (UnionBy o g1 g2)) Source Github #

Instances

Instances details
(SymMonoidal k, Unmerge g1 ('(m, b) ': g2), KnownObj a, KnownObj b, Mul ('(n, a) ': Union g1 ('(m, b) ': g2)) ~ (Mul (Union g1 ('(m, b) ': g2)) ':** a)) => UnmergeBy 'GT ('(n, a) ': g1 :: [(Nat, SYN k)]) ('(m, b) ': g2 :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

unmergeBy :: (Interp (Mul ('(n, a) ': g1)) ** Interp (Mul ('(m, b) ': g2))) ~> Interp (Mul (UnionBy 'GT ('(n, a) ': g1) ('(m, b) ': g2))) Source Github #

(Monoidal k, Unmerge ('(n, a) ': g1) g2, KnownObj a, KnownObj b, Mul ('(m, b) ': Union ('(n, a) ': g1) g2) ~ (Mul (Union ('(n, a) ': g1) g2) ':** b)) => UnmergeBy 'LT ('(n, a) ': g1 :: [(Nat, SYN k)]) ('(m, b) ': g2 :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

unmergeBy :: (Interp (Mul ('(n, a) ': g1)) ** Interp (Mul ('(m, b) ': g2))) ~> Interp (Mul (UnionBy 'LT ('(n, a) ': g1) ('(m, b) ': g2))) Source Github #

class (KnownCtx g, KnownCtx h) => Thin (g :: Ctx k) (h :: Ctx k) where Source Github #

Keep the variables of g that h has and discard the others, for an alternative of the additives that does not use all the variables of the other. Every variable of h must be in g.

Methods

thin :: Interp (Mul g) ~> Interp (Mul h) Source Github #

Instances

Instances details
Monoidal k => Thin ('[] :: [(Nat, SYN k)]) ('[] :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

thin :: Interp (Mul ('[] :: [(Nat, SYN k)])) ~> Interp (Mul ('[] :: [(Nat, SYN k)])) Source Github #

(Monoidal k, Comonoid (Interp a), KnownObj a, Thin g ('[] :: [(Nat, SYN k)])) => Thin ('(n, a) ': g :: [(Nat, SYN k)]) ('[] :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

thin :: Interp (Mul ('(n, a) ': g)) ~> Interp (Mul ('[] :: [(Nat, SYN k)])) Source Github #

(KnownObj a, KnownObj b, KnownCtx g, KnownCtx h, ThinBy (CmpNat n m) ('(n, a) ': g) ('(m, b) ': h)) => Thin ('(n, a) ': g :: [(Natural, SYN k)]) ('(m, b) ': h :: [(Natural, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

thin :: Interp (Mul ('(n, a) ': g)) ~> Interp (Mul ('(m, b) ': h)) Source Github #

class (KnownCtx g, KnownCtx h) => ThinBy (o :: Ordering) (g :: Ctx k) (h :: Ctx k) where Source Github #

thin for two non-empty contexts, by which of the two has the larger head id.

Methods

thinBy :: Interp (Mul g) ~> Interp (Mul h) Source Github #

Instances

Instances details
(Monoidal k, KnownObj a, a ~ b, Thin g h) => ThinBy 'EQ ('(n, a) ': g :: [(Nat, SYN k)]) ('(m, b) ': h :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

thinBy :: Interp (Mul ('(n, a) ': g)) ~> Interp (Mul ('(m, b) ': h)) Source Github #

(Monoidal k, Comonoid (Interp a), KnownObj a, KnownObj b, Thin g ('(m, b) ': h)) => ThinBy 'GT ('(n, a) ': g :: [(Nat, SYN k)]) ('(m, b) ': h :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

thinBy :: Interp (Mul ('(n, a) ': g)) ~> Interp (Mul ('(m, b) ': h)) Source Github #

class KnownCtx r => BindVar (n :: Nat) (a :: SYN k) (g :: Ctx k) (r :: Ctx k) | n g -> r where Source Github #

A binder's variable n on the right of r, what the body uses besides it, given the body's context g: snoc if the body uses the variable, and its counit otherwise. The binder's variable is the newest in scope, so it can only be at the head of g. The functional dependency, rather than a type family, gives r, so that a binder costs one comparison of ids.

Methods

bindVar :: (Interp (Mul r) ** Interp a) ~> Interp (Mul g) Source Github #

Instances

Instances details
(Monoidal k, Comonoid (Interp a), KnownObj a) => BindVar n (a :: SYN k) ('[] :: [(Nat, SYN k)]) ('[] :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

bindVar :: (Interp (Mul ('[] :: [(Nat, SYN k)])) ** Interp a) ~> Interp (Mul ('[] :: [(Nat, SYN k)])) Source Github #

(KnownCtx r, BindVarBy (CmpNat n m) n a ('(m, b) ': g) r) => BindVar n (a :: SYN k) ('(m, b) ': g :: [(Natural, SYN k)]) (r :: Ctx k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

bindVar :: (Interp (Mul r) ** Interp a) ~> Interp (Mul ('(m, b) ': g)) Source Github #

class BindVarBy (o :: Ordering) (n :: Nat) (a :: SYN k) (g :: Ctx k) (r :: Ctx k) | o n g -> r where Source Github #

bindVar for a non-empty context, by whether its head is the new variable.

Instances

Instances details
(Monoidal k, KnownObj a, a ~ b, KnownCtx g) => BindVarBy 'EQ n (a :: SYN k) ('(m, b) ': g :: [(Nat, SYN k)]) (g :: Ctx k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

bindVarBy :: (Interp (Mul g) ** Interp a) ~> Interp (Mul ('(m, b) ': g)) Source Github #

(Monoidal k, Comonoid (Interp a), KnownObj a, KnownObj b, KnownCtx g) => BindVarBy 'GT n (a :: SYN k) ('(m, b) ': g :: [(Nat, SYN k)]) ('(m, b) ': g :: [(Nat, SYN k)]) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Context

Methods

bindVarBy :: (Interp (Mul ('(m, b) ': g)) ** Interp a) ~> Interp (Mul ('(m, b) ': g)) Source Github #

type family HeadId (g :: Ctx k) :: Nat where ... Source Github #

Equations

HeadId ('(n, a) ': g :: [(Nat, SYN k)]) = n 

type family Minus (g :: Ctx k) (h :: Ctx k) :: Ctx k where ... Source Github #

The variables of g whose ids are not in h.

Equations

Minus ('[] :: [(Nat, SYN k)]) (h :: Ctx k) = '[] :: [(Nat, SYN k)] 
Minus (g :: Ctx k) ('[] :: [(Nat, SYN k)]) = g 
Minus ('(n, a) ': g :: [(Nat, SYN k)]) ('(m, b) ': h :: [(Nat, SYN k)]) = MinusBy (CmpNat n m) ('(n, a) ': g) ('(m, b) ': h) 

type family MinusBy (o :: Ordering) (g :: Ctx k) (h :: Ctx k) :: Ctx k where ... Source Github #

Equations

MinusBy 'GT (x ': g :: [(Nat, SYN k)]) (h :: Ctx k) = x ': Minus g h 
MinusBy 'EQ (x ': g :: [(Nat, SYN k)]) (y ': h :: [(Nat, SYN k)]) = Minus g h 
MinusBy 'LT (g :: Ctx k) (y ': h :: [(Nat, SYN k)]) = Minus g h 

type Inter (g :: Ctx k) (h :: Ctx k) = Minus g (Minus g h) Source Github #

The variables of g whose ids are in h.