| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
Proarrow.Tools.SMC.Internal.Pattern
Description
Internal module of Proarrow.Tools.SMC: patterns and binders. It exports everything, also what the public module keeps hidden.
Synopsis
- toSMC :: forall {k} (a :: SYN k) (b :: SYN k) t cont. (Monoidal k, Binds ((~>) :: CAT k) 0 ('[] :: [(Nat, SYN k)]) a b t cont) => (t -> cont) -> Interp a ~> Interp b
- toSMC1 :: forall {k} (a :: k) (b :: k) t cont. (Monoidal k, Binds ((~>) :: CAT k) 0 ('[] :: [(Nat, SYN k)]) ('F a) ('F b) t cont) => (t -> cont) -> a ~> b
- proc :: forall {k} (a :: SYN k) (b :: SYN k) t cont p. (MonoidalProfunctor p, Binds p 0 ('[] :: [(Nat, SYN k)]) a b t cont) => (t -> cont) -> p (Interp a) (Interp b)
- liftF :: forall {k} (a :: SYN k) (b :: k) t p (d :: Nat) (g :: Ctx k). (Promonad p, BuildTuple p t g a) => p (Interp a) b -> t -> TermP p d g ('F b)
- (-<) :: forall {k} (a :: SYN k) (b :: k) t p (d :: Nat) (g :: Ctx k). (Promonad p, BuildTuple p t g a) => p (Interp a) b -> t -> TermP p d g ('F b)
- returnA :: forall {k} p (a :: k). (Promonad p, Ob a) => p a a
- type Up (a :: SYN k) = 'Not ('Not a)
- runUp :: forall {k} (d :: Nat) (g :: Ctx k) (r :: Ctx k) (a :: SYN k) (y :: SYN k). (Dialogue k, KnownObj a, KnownObj y, Merge g r) => Term d g (Up a) -> ((Interp (Mul r) ** Interp a) ~> Interp ('Not y)) -> Term d (Union g r) ('Not y)
- ret :: forall {k} {p :: k +-> k} (a :: SYN k) t (d :: Nat) (g :: Ctx k). (Dialogue k, Profunctor p, KnownObj a, BuildTuple p t g a) => t -> TermP p d g (Up a)
- type Tuple (p :: CAT k) t (a :: SYN k) = BuildTuple p t (CtxOf t :: Ctx k) a
- class BuildTuple (p :: CAT k) t (g :: Ctx k) (a :: SYN k) where
- class (KnownObj a, KnownCtx g) => Binds (p :: CAT k) (n :: Nat) (g :: Ctx k) (a :: SYN k) (b :: SYN k) t cont where
- class BindPat (p :: CAT k) m t cont r | m -> p where
- bindPat :: m -> (t -> cont) -> r
- class Pat (p :: CAT k) t (d :: Nat) (g :: Ctx k) (a :: SYN k) (g' :: Ctx k) (c :: SYN k) (gr :: Ctx k) where
- type family PSize t :: Nat where ...
Documentation
toSMC :: forall {k} (a :: SYN k) (b :: SYN k) t cont. (Monoidal k, Binds ((~>) :: CAT k) 0 ('[] :: [(Nat, SYN k)]) a b t cont) => (t -> cont) -> Interp a ~> Interp b Source Github #
Compile a function on terms to a morphism. The function receives the input through a pattern
(see Patterns), so () compiles a term without inputs and a tuple takes a tensor apart.
toSMC1 :: forall {k} (a :: k) (b :: k) t cont. (Monoidal k, Binds ((~>) :: CAT k) 0 ('[] :: [(Nat, SYN k)]) ('F a) ('F b) t cont) => (t -> cont) -> a ~> b Source Github #
proc :: forall {k} (a :: SYN k) (b :: SYN k) t cont p. (MonoidalProfunctor p, Binds p 0 ('[] :: [(Nat, SYN k)]) a b t cont) => (t -> cont) -> p (Interp a) (Interp b) Source Github #
Compile a function on terms to an arrow of the promonad p, as toSMC does for the morphisms
of the category, which are the case p = (. The terms' computations are arrows of ~>)p,
lifted with (-<) or lift, and run in the order they are written; variables are values,
which the category's structure copies and discards. This mirrors proc in Haskell's arrow
notation, whose Arrows extension must be disabled.
liftF :: forall {k} (a :: SYN k) (b :: k) t p (d :: Nat) (g :: Ctx k). (Promonad p, BuildTuple p t g a) => p (Interp a) b -> t -> TermP p d g ('F b) Source Github #
(-<) :: forall {k} (a :: SYN k) (b :: k) t p (d :: Nat) (g :: Ctx k). (Promonad p, BuildTuple p t g a) => p (Interp a) b -> t -> TermP p d g ('F b) infixr 0 Source Github #
type Up (a :: SYN k) = 'Not ('Not a) Source Github #
The shift of a positive type to a negative one: a computation that produces an a. A term of
it is a consumer of consumers of a, so in a category with it is the
continuation passing type Dual a = a ~~> r(a -> r) -> r.
runUp :: forall {k} (d :: Nat) (g :: Ctx k) (r :: Ctx k) (a :: SYN k) (y :: SYN k). (Dialogue k, KnownObj a, KnownObj y, Merge g r) => Term d g (Up a) -> ((Interp (Mul r) ** Interp a) ~> Interp ('Not y)) -> Term d (Union g r) ('Not y) Source Github #
Run a computation against the rest of a block. The body is what the rest does with the value,
given the context r; it becomes a consumer of the computation, whose context g joins. What
the binds of a computation share, the counterpart of bound.
ret :: forall {k} {p :: k +-> k} (a :: SYN k) t (d :: Nat) (g :: Ctx k). (Dialogue k, Profunctor p, KnownObj a, BuildTuple p t g a) => t -> TermP p d g (Up a) Source Github #
type Tuple (p :: CAT k) t (a :: SYN k) = BuildTuple p t (CtxOf t :: Ctx k) a Source Github #
A term built from a tuple of terms, by the type it is expected to have: a term is itself,
() is the monoidal unit, a pair at a tensor is the tensor of its parts, and a pair at a
computation is the computation of the pair at Up aa. A tuple of three to six stands for pairs nested to the left, as in
patterns. The parts may come from different binding depths; the result adopts the depth
where it is used, and their contexts are merged.
class BuildTuple (p :: CAT k) t (g :: Ctx k) (a :: SYN k) where Source Github #
Build a tuple with its context inferred alongside its type. Keeping the context a parameter allows constant arrows of an abstract category to use the empty context.
Instances
| (MonoidalProfunctor p, a ~ ('I :: SYN k), g ~ ('[] :: [(Nat, SYN k)])) => BuildTuple (p :: k +-> k) () (g :: [(Nat, SYN k)]) (a :: SYN k) Source Github # | The empty tuple is the monoidal unit and uses no variables. |
| ToTerm p t (DepthOf t) g a => BuildTuple (p :: CAT k) t (g :: Ctx k) (a :: SYN k) Source Github # | A term keeps its context and type, adapting to the depth where it is used. Variable ids in the context are unchanged. |
| (MonoidalProfunctor p, a ~ (a1 ':** a2), BuildTuple p x g1 a1, BuildTuple p y g2 a2, Merge g1 g2, g ~ Union g1 g2) => BuildTuple (p :: k +-> k) (x, y) (g :: Ctx k) (a :: SYN k) Source Github # | A pair at a tensor is the tensor of its parts. |
| (Dialogue k, Profunctor p, KnownObj a, BuildTuple p (x, y) g a) => BuildTuple (p :: k +-> k) (x, y) (g :: Ctx k) ('Not ('Not a) :: SYN k) Source Github # | A pair at a computation is the computation of the pair at the value. |
| BuildTuple p ((x, y), z) g a => BuildTuple (p :: CAT k) (x, y, z) (g :: Ctx k) (a :: SYN k) Source Github # | |
| BuildTuple p ((w, x, y), z) g a => BuildTuple (p :: CAT k) (w, x, y, z) (g :: Ctx k) (a :: SYN k) Source Github # | |
| BuildTuple p ((v, w, x, y), z) g a => BuildTuple (p :: CAT k) (v, w, x, y, z) (g :: Ctx k) (a :: SYN k) Source Github # | |
| BuildTuple p ((u, v, w, x, y), z) g a => BuildTuple (p :: CAT k) (u, v, w, x, y, z) (g :: Ctx k) (a :: SYN k) Source Github # | |
class (KnownObj a, KnownCtx g) => Binds (p :: CAT k) (n :: Nat) (g :: Ctx k) (a :: SYN k) (b :: SYN k) t cont where Source Github #
The pattern t of a binder: it takes apart the variable (n, a), and the binder's body
cont then gives a term at depth n + 1 with type b, whose context is g and possibly that
variable. Both the variable's type and the rest of the context must be known.
class BindPat (p :: CAT k) m t cont r | m -> p where Source Github #
A term on the right hand side taken apart by the pattern of the continuation. The types of the continuation and the result are matched with equalities, so that the instance is chosen as soon as the right hand side is known.
class Pat (p :: CAT k) t (d :: Nat) (g :: Ctx k) (a :: SYN k) (g' :: Ctx k) (c :: SYN k) (gr :: Ctx k) where Source Github #
A pattern: a variable, (), or a pair of patterns. A tuple of three to six stands for pairs
nested to the left, as a is: :** b :** c(x, y, z) is ((x, y), z). Binding it at depth
d to a term with context g and type a, with a continuation with context g' and type c,
gives a term with context gr, which each instance fixes. A pair or () at a computation,
, runs it and matches its value, so Up ac is then negative.
Instances
| (MonoidalProfunctor p, a ~ ('I :: SYN k), KnownObj c, Merge g g', gr ~ Union g g') => Pat (p :: k +-> k) () d (g :: Ctx k) (a :: SYN k) (g' :: Ctx k) (c :: SYN k) (gr :: Ctx k) Source Github # | The pattern |
| (t ~ TermP p (DepthOf t) g a, gr ~ g') => Pat (p :: CAT k) t d (g :: Ctx k) (a :: SYN k) (g' :: Ctx k) (c :: SYN k) (gr :: Ctx k) Source Github # | A variable pattern names the right hand side, which is always a variable. If the body does not use it, the binder discards it. |
| (p ~ Hom k, Dialogue k, KnownObj y, c ~ 'Not y, Merge g g', gr ~ Union g g') => Pat (p :: CAT k) () d (g :: Ctx k) ('Not ('Not ('I :: SYN k)) :: SYN k) (g' :: Ctx k) (c :: SYN k) (gr :: Ctx k) Source Github # | The pattern |
| (Promonad p, MonoidalProfunctor p, a ~ (a1 ':** a2), KnownObj a1, KnownObj a2, Pat p y ((d + 2) + PSize x) '['(d + 1, a2)] a2 g' c gy, Pat p x (d + 2) '['(d, a1)] a1 gy c gxy, (((d + 2) + PSize x) + PSize y) ~ (d + PSize (x, y)), BindVar (d + 1) a2 gxy r1, BindVar d a1 r1 r, Merge r g, gr ~ Union r g) => Pat (p :: CAT k) (x, y) d (g :: Ctx k) (a :: SYN k) (g' :: Ctx k) (c :: SYN k) (gr :: Ctx k) Source Github # | |
| (a ~ (a1 ** a2), Pat p (x, y) d g ('F a1 ':** 'F a2) g' c gr) => Pat (p :: CAT k) (x, y) d (g :: Ctx k) ('F a :: SYN k) (g' :: Ctx k) (c :: SYN k) (gr :: Ctx k) Source Github # | A pair pattern at an embedded tensor exposes its two embedded components. The tensor pattern supplies the binding and context operations. |
| (p ~ Hom k, Dialogue k, KnownObj a, KnownObj y, c ~ 'Not y, Pat p (x, y') d '['(d, a)] a g' c gp, BindVar d a gp r, Merge g r, gr ~ Union g r) => Pat (p :: CAT k) (x, y') d (g :: Ctx k) ('Not ('Not a) :: SYN k) (g' :: Ctx k) (c :: SYN k) (gr :: Ctx k) Source Github # | A pair pattern at a computation runs it and takes its value apart. The value needs no variable of its own: the pattern's variables take the ids it would have taken. |
| Pat p ((x, y), z) d g a g' c gr => Pat (p :: CAT k) (x, y, z) d (g :: Ctx k) (a :: SYN k) (g' :: Ctx k) (c :: SYN k) (gr :: Ctx k) Source Github # | |
| Pat p ((w, x, y), z) d g a g' c gr => Pat (p :: CAT k) (w, x, y, z) d (g :: Ctx k) (a :: SYN k) (g' :: Ctx k) (c :: SYN k) (gr :: Ctx k) Source Github # | |
| Pat p ((v, w, x, y), z) d g a g' c gr => Pat (p :: CAT k) (v, w, x, y, z) d (g :: Ctx k) (a :: SYN k) (g' :: Ctx k) (c :: SYN k) (gr :: Ctx k) Source Github # | |
| Pat p ((u, v, w, x, y), z) d g a g' c gr => Pat (p :: CAT k) (u, v, w, x, y, z) d (g :: Ctx k) (a :: SYN k) (g' :: Ctx k) (c :: SYN k) (gr :: Ctx k) Source Github # | |