| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
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
- type Ctx k = [(Nat, SYN k)]
- type family Mul (g :: Ctx k) :: SYN k where ...
- class KnownCtx (g :: Ctx k) where
- ctxOb :: forall {k} (g :: Ctx k). (Monoidal k, KnownCtx g) => Obj (Interp (Mul g))
- 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))
- type family Union (g1 :: Ctx k) (g2 :: Ctx k) :: Ctx k where ...
- type family UnionBy (o :: Ordering) (g1 :: Ctx k) (g2 :: Ctx k) :: Ctx k where ...
- 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)
- class (KnownCtx g1, KnownCtx g2) => Merge (g1 :: Ctx k) (g2 :: Ctx k) where
- class (KnownCtx g1, KnownCtx g2) => MergeBy (o :: Ordering) (g1 :: Ctx k) (g2 :: Ctx k) where
- class (KnownCtx g1, KnownCtx g2) => Unmerge (g1 :: Ctx k) (g2 :: Ctx k) where
- class (KnownCtx g1, KnownCtx g2) => UnmergeBy (o :: Ordering) (g1 :: Ctx k) (g2 :: Ctx k) where
- class (KnownCtx g, KnownCtx h) => Thin (g :: Ctx k) (h :: Ctx k) where
- class (KnownCtx g, KnownCtx h) => ThinBy (o :: Ordering) (g :: Ctx k) (h :: Ctx k) where
- class KnownCtx r => BindVar (n :: Nat) (a :: SYN k) (g :: Ctx k) (r :: Ctx k) | n g -> r where
- class BindVarBy (o :: Ordering) (n :: Nat) (a :: SYN k) (g :: Ctx k) (r :: Ctx k) | o n g -> r where
- type family HeadId (g :: Ctx k) :: Nat where ...
- type family Minus (g :: Ctx k) (h :: Ctx k) :: Ctx k where ...
- type family MinusBy (o :: Ordering) (g :: Ctx k) (h :: Ctx k) :: Ctx k where ...
- type Inter (g :: Ctx k) (h :: Ctx k) = Minus g (Minus g h)
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.
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 reduce.Mul ('(n, a) ': g)
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
| KnownCtx ('[] :: [(Nat, SYN k)]) Source Github # | |
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 # | |
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.
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.
Instances
| (Monoidal k, KnownCtx g2) => Merge ('[] :: [(Nat, SYN k)]) (g2 :: Ctx k) Source Github # | |
| (Monoidal k, KnownCtx ('(n, a) ': g1)) => Merge ('(n, a) ': g1 :: [(Nat, SYN k)]) ('[] :: [(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 # | |
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
| (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. |
| (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 # | |
| (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 # | |
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
| (Monoidal k, KnownCtx g2) => Unmerge ('[] :: [(Nat, SYN k)]) (g2 :: Ctx k) Source Github # | |
| (Monoidal k, KnownCtx ('(n, a) ': g1)) => Unmerge ('(n, a) ': g1 :: [(Nat, SYN k)]) ('[] :: [(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 # | |
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
| (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 # | |
| (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 # | |
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.
Instances
| Monoidal k => Thin ('[] :: [(Nat, SYN k)]) ('[] :: [(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 # | |
| (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 # | |
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.
Instances
| (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 # | |
| (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 # | |
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.
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
| (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 # | |
| (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 # | |
type family Minus (g :: Ctx k) (h :: Ctx k) :: Ctx k where ... Source Github #
The variables of g whose ids are not in h.