proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Tools.SMC.Internal.Term

Description

Internal module of Proarrow.Tools.SMC: terms and the operations that need no binder. It exports everything, also what the public module keeps hidden.

Synopsis

Documentation

data TermP (p :: CAT k) (d :: Nat) (g :: Ctx k) (a :: SYN k) where Source Github #

A term at binding depth d with context g and type a, whose computations are arrows of the promonad p: an arrow of p from the tensor of the context to a. Variables and the structure of contexts are morphisms of the category k, which p takes in with lmap and rmap. At p = (~>) this is Term.

Constructors

MkTerm :: forall {k} (p :: CAT k) (g :: Ctx k) (a :: SYN k) (d :: Nat). p (Interp (Mul g)) (Interp a) -> TermP p d g a 

Instances

Instances details
BindPat p (TermP p d g a) () cont r => BindTerm (p :: CAT k) () (TermP p d g a) cont r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

bindTerm :: TermP p d g a -> (() -> cont) -> r Source Github #

(Promonad p, MonoidalProfunctor p, Binds p d r a b t cont, Merge r g, r' ~ TermP p d (Union r g) b) => BindTerm (p :: CAT k) t (TermP p d g a) cont r' Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

bindTerm :: TermP p d g a -> (t -> cont) -> r' Source Github #

BindPat p (TermP p d g a) (x, y) cont r => BindTerm (p :: CAT k) (x, y) (TermP p d g a) cont r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

bindTerm :: TermP p d g a -> ((x, y) -> cont) -> r Source Github #

BindPat p (TermP p d g a) (x, y, z) cont r => BindTerm (p :: CAT k) (x, y, z) (TermP p d g a) cont r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

bindTerm :: TermP p d g a -> ((x, y, z) -> cont) -> r Source Github #

BindPat p (TermP p d g a) (w, x, y, z) cont r => BindTerm (p :: CAT k) (w, x, y, z) (TermP p d g a) cont r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

bindTerm :: TermP p d g a -> ((w, x, y, z) -> cont) -> r Source Github #

(KnownObj a, KnownObj b, Merge g1 g2, ToTerm p x d g2 a, r ~ TermP p d (Union g1 g2) b) => Apply (p :: CAT k) (TermP p d g1 (a ':-> b)) x r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Closed

Methods

(!) :: TermP p d g1 (a ':-> b) -> x -> r Source Github #

(KnownObj a, KnownObj b, Merge g1 g2, f ~ (Interp a ~~> Interp b), ToTerm p x d g2 a, r ~ TermP p d (Union g1 g2) b) => Apply (p :: CAT k) (TermP p d g1 ('F f)) x r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Closed

Methods

(!) :: TermP p d g1 ('F f) -> x -> r Source Github #

(p ~ Hom k, Dialogue k, KnownObj y, Merge g r, Negative (TyOf cont :: SYN k) y, Binds p d r a (TyOf cont :: SYN k) t cont, r' ~ TermP p d (Union g r) ('Not y)) => Bind (p :: CAT k) (TermP p d g ('Not ('Not a))) t cont r' Source Github #

A computation on the right hand side runs first, and the rest of the block is negative.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

(>>=) :: TermP p d g ('Not ('Not a)) -> (t -> cont) -> r' Source Github #

BindTerm p t (TermP p d g a) cont r => Bind (p :: CAT k) (TermP p d g a) t cont r Source Github #

A term on the right hand side is taken apart by the pattern. Incoherent, so that it is chosen as soon as the right hand side is known, unless the right hand side is a computation.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

(>>=) :: TermP p d g a -> (t -> cont) -> r Source Github #

(ToTerm p cont (d + PSize t) gc b, r ~ TermP p d gr b, Pat p t d g a gc b gr) => BindPat (p :: CAT k) (TermP p d g a) t cont r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Pattern

Methods

bindPat :: TermP p d g a -> (t -> cont) -> r Source Github #

TermP q d' g' a' ~ TermP p d g a => ToTerm (p :: CAT k2) (TermP q d' g' a') d (g :: Ctx k2) (a :: SYN k2) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Term

Methods

toTerm :: TermP q d' g' a' -> TermP p d g a Source Github #

(Bind p (TermP p d g a) t cont r', r ~ Ret tt r') => Bind (p :: CAT k) (TermP p d g a) t (Ret tt cont) r Source Github #

The statement of a rec block, whose continuation is its return.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

(>>=) :: TermP p d g a -> (t -> Ret tt cont) -> r Source Github #

BindPat p (TermP p d g a) (v, w, x, y, z) cont r => BindTerm (p :: CAT k) (v, w, x, y, z) (TermP p d g a) cont r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

bindTerm :: TermP p d g a -> ((v, w, x, y, z) -> cont) -> r Source Github #

BindPat p (TermP p d g a) (u, v, w, x, y, z) cont r => BindTerm (p :: CAT k) (u, v, w, x, y, z) (TermP p d g a) cont r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

bindTerm :: TermP p d g a -> ((u, v, w, x, y, z) -> cont) -> r Source Github #

TupleProfunctor (TermP p d g a ': ts) (p :: CAT k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

(Promonad p, KnownObj a) => RecVars k (TermP p d '['(n, a)] a) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Associated Types

type Vars k (TermP p d '['(n, a)] a) 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

type Vars k (TermP p d '['(n, a)] a) = '['(n, a)]

Methods

recVars :: TermP p d '['(n, a)] a Source Github #

t' ~ TermP p d' g a => AnyDepth (TermP p d g a) t' Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

type Vars k (TermP p d '['(n, a)] a) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

type Vars k (TermP p d '['(n, a)] a) = '['(n, a)]

type Term (d :: Nat) (g :: Ctx k) (a :: SYN k) = TermP ((~>) :: CAT k) d g a Source Github #

A term whose computations are the morphisms of the category itself.

class ToTerm (p :: CAT k) t (d :: Nat) (g :: Ctx k) (a :: SYN k) | p t -> g a where Source Github #

A term, a constant arrow from the monoidal unit, or a tuple of these. Constants and the empty tuple use no variables; pairs merge their components' contexts. Base-category constants enter a promonad through arr; arrows already in it are kept. Converting a term here keeps its binding depth, unlike tuple construction.

Methods

toTerm :: t -> TermP p d g a Source Github #

Explicit conversion for helpers whose result must be a concrete term.

Instances

Instances details
(MonoidalProfunctor p, g ~ ('[] :: [(Nat, SYN k)]), a ~ ('I :: SYN k)) => ToTerm (p :: k +-> k) () d (g :: [(Nat, SYN k)]) (a :: SYN k) Source Github #

The empty tuple is the monoidal unit.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Term

Methods

toTerm :: () -> TermP p d g a Source Github #

t ~ TermP p d g a => ToTerm (p :: CAT k) t d (g :: Ctx k) (a :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Term

Methods

toTerm :: t -> TermP p d g a Source Github #

(MonoidalProfunctor p, ToTerm p x d g1 a1, ToTerm p y d g2 a2, Merge g1 g2, g ~ Union g1 g2, a ~ (a1 ':** a2)) => ToTerm (p :: k +-> k) (x, y) d (g :: Ctx k) (a :: SYN k) Source Github #

A pair combines its components as a tensor, merging their contexts.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Term

Methods

toTerm :: (x, y) -> TermP p d g a Source Github #

(q x y ~ r (Unit :: k3) b, LiftArrow p r, g ~ ('[] :: [(Nat, SYN k3)]), a ~ 'F b) => ToTerm (p :: CAT k3) (q x y) d (g :: [(Nat, SYN k3)]) (a :: SYN k3) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Term

Methods

toTerm :: q x y -> TermP p d g a Source Github #

ToTerm p ((x, y), z) d g a => ToTerm (p :: CAT k) (x, y, z) d (g :: Ctx k) (a :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Term

Methods

toTerm :: (x, y, z) -> TermP p d g a Source Github #

ToTerm p ((w, x, y), z) d g a => ToTerm (p :: CAT k) (w, x, y, z) d (g :: Ctx k) (a :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Term

Methods

toTerm :: (w, x, y, z) -> TermP p d g a Source Github #

ToTerm p ((v, w, x, y), z) d g a => ToTerm (p :: CAT k) (v, w, x, y, z) d (g :: Ctx k) (a :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Term

Methods

toTerm :: (v, w, x, y, z) -> TermP p d g a Source Github #

TermP q d' g' a' ~ TermP p d g a => ToTerm (p :: CAT k2) (TermP q d' g' a') d (g :: Ctx k2) (a :: SYN k2) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Term

Methods

toTerm :: TermP q d' g' a' -> TermP p d g a Source Github #

ToTerm p ((u, v, w, x, y), z) d g a => ToTerm (p :: CAT k) (u, v, w, x, y, z) d (g :: Ctx k) (a :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Term

Methods

toTerm :: (u, v, w, x, y, z) -> TermP p d g a Source Github #

class LiftArrow (p :: CAT k) (q :: CAT k) where Source Github #

Methods

liftArrow :: forall (a :: k) (b :: k). q a b -> p a b Source Github #

Instances

Instances details
LiftArrow (p :: CAT k) (p :: CAT k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Term

Methods

liftArrow :: forall (a :: k) (b :: k). p a b -> p a b Source Github #

(Promonad p, q ~ Hom k) => LiftArrow (p :: CAT k) (q :: CAT k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Term

Methods

liftArrow :: forall (a :: k) (b :: k). q a b -> p a b Source Github #

var :: forall {k} (n :: Nat) (a :: SYN k) (d :: Nat) (p :: CAT k). (Promonad p, KnownObj a) => TermP p d '['(n, a)] a Source Github #

The variable with id n: the identity on its type.

dup :: forall {k} (s :: SYN k) (d :: Nat) (g :: Ctx k) (p :: k +-> k). (Profunctor p, Comonoid (Interp s)) => TermP p d g s -> TermP p d g (s ':** s) Source Github #

Copy a term whose type is a comonoid: (x1, x2) <- dup x. Using a variable twice copies it too, but needs a CocommutativeComonoid; dup needs only a Comonoid, and its two copies come out in the order of comult.

drop :: forall {k} (s :: SYN k) (d :: Nat) (g :: Ctx k) (p :: k +-> k). (Profunctor p, Comonoid (Interp s)) => TermP p d g s -> TermP p d g ('I :: SYN k) Source Github #

Discard a term whose type is a comonoid: () <- drop t. A variable that is not used is discarded without it.

lift :: forall {k} (a :: SYN k) (b :: SYN k) (d :: Nat) (g :: Ctx k) p t. (Promonad p, ToTerm p t d g a) => p (Interp a) (Interp b) -> t -> TermP p d g b Source Github #

Lift an arrow of the promonad to a function on terms, constants or tuples: it runs after the input.

rmapT :: forall {k} (a :: SYN k) (b :: SYN k) (d :: Nat) (g :: Ctx k) (p :: CAT k). Profunctor p => (Interp a ~> Interp b) -> TermP p d g a -> TermP p d g b Source Github #

Lift a morphism of the category to a function on terms, with rmap. For p = (~>) this is lift; for other promonads it is how the structure of k acts on terms.

(**) :: forall {k} (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k) (a :: SYN k) (b :: SYN k) (p :: CAT k). (MonoidalProfunctor p, Merge g1 g2) => TermP p d g1 a -> TermP p d g2 b -> TermP p d (Union g1 g2) (a ':** b) infixl 7 Source Github #

Two concrete terms side by side. A variable both use is copied. With effects, the left term runs first. Use tuples to combine components through ToTerm.

push2 :: forall {k} (n :: Natural) (a :: SYN k) (b :: SYN k) (g' :: Ctx k) (r1 :: Ctx k) (r :: Ctx k) (g :: Ctx k) p. (Promonad p, MonoidalProfunctor p, KnownObj a, KnownObj b, BindVar (n + 1) b g' r1, BindVar n a r1 r, Merge r g) => p (Interp (Mul g)) (Interp a ** Interp b) -> p (Interp (Mul (Union r g))) (Interp (Mul g')) Source Github #

Two new variables n and n + 1, of types a and b, for the body of a split whose context is g': the tensor a :** b, given from the context g, next to r, what the body uses besides them.

split :: forall {k} (d :: Natural) (g :: Ctx k) (g' :: Ctx k) (r1 :: Ctx k) (r :: Ctx k) (a :: SYN k) (b :: SYN k) (c :: SYN k) (da :: Nat) (db :: Nat) (p :: CAT k). (Promonad p, MonoidalProfunctor p, KnownObj a, KnownObj b, BindVar (d + 1) b g' r1, BindVar d a r1 r, Merge r g) => TermP p d g (a ':** b) -> (TermP p da '['(d, a)] a -> TermP p db '['(d + 1, b)] b -> TermP p (d + 2) g' c) -> TermP p d (Union r g) c Source Github #

Take a tensor apart: the continuation gets a variable for each side.

unit :: forall {k} (d :: Nat) (p :: CAT k). MonoidalProfunctor p => TermP p d ('[] :: [(Nat, SYN k)]) ('I :: SYN k) Source Github #

The unit, which uses no variables.

recast :: forall {k} (a :: SYN k) (b :: SYN k) (d :: Nat) (d' :: Nat) (g :: Ctx k) (p :: CAT k). Interp a ~ Interp b => TermP p d g a -> TermP p d' g b Source Github #

The same morphism at another type expression for the same object, and at any depth: between F (a ** b) and F a :** F b, say, so that a pattern can take it apart, or between a type and its Dn. The polarity may change, the morphism does not.

type family DepthOf t :: Nat where ... Source Github #

Equations

DepthOf (TermP p d g a) = d 

type family CtxOf t :: Ctx k where ... Source Github #

Equations

CtxOf (TermP p d g a) = g 
CtxOf () = '[] :: [(Nat, SYN k)] 
CtxOf (x, y) = Union (CtxOf x :: Ctx k) (CtxOf y :: Ctx k) 
CtxOf (x, y, z) = CtxOf ((x, y), z) :: Ctx k 
CtxOf (w, x, y, z) = CtxOf ((w, x, y), z) :: Ctx k 
CtxOf (v, w, x, y, z) = CtxOf ((v, w, x, y), z) :: Ctx k 
CtxOf (u, v, w, x, y, z) = CtxOf ((u, v, w, x, y), z) :: Ctx k 
CtxOf (p x y) = '[] :: [(Nat, SYN k1)] 

type family TyOf t :: SYN k where ... Source Github #

Equations

TyOf (TermP p d g a) = a 
TyOf () = 'I :: SYN k 
TyOf (x, y) = (TyOf x :: SYN k) ':** (TyOf y :: SYN k) 
TyOf (x, y, z) = TyOf ((x, y), z) :: SYN k 
TyOf (w, x, y, z) = TyOf ((w, x, y), z) :: SYN k 
TyOf (v, w, x, y, z) = TyOf ((v, w, x, y), z) :: SYN k 
TyOf (u, v, w, x, y, z) = TyOf ((u, v, w, x, y), z) :: SYN k 
TyOf (p x y) = 'F y