proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Tools.CCC

Description

Cartesian terms, using the syntax and binders of Proarrow.Tools.SMC in PROD k. Its tensor is the product of k, independently of any monoidal structure on k itself. F embeds a base object, a :** b is a product, and a :-> b is the exponential of PROD k. toCCC compiles a function on terms and unwraps the resulting arrow into k.

Each operation asks only for the structure it uses: products for pairing and binding, Closed (PROD k) for lam and (!), coproducts for inl and inr, and Distributive (PROD k) for caseOf. Copying and discarding are supplied by products. The patterns, contexts and QualifiedDo notation are those of SMC; see Proarrow.Tools.SMC for their use, including recast across binding depths.

import Prelude hiding ((**))
import Proarrow.Tools.CCC (SYN (..), type F, toCCC, (**))

swapProduct = toCCC @(F a :** F b) @(F b :** F a) (\(a, b) -> (b, a))
Synopsis

Types

data SYN k Source Github #

Type expressions over the objects of k: an object of k, the unit, the tensor, the internal hom and the negation, and the additives: the product and its unit Top, and the coproduct and its unit Zero.

The negation gives the types a polarity: a type is negative when it is a Not, and positive otherwise. A term of a positive type is a value, and a term of a negative type is a consumer of what it negates. Up shifts a positive type to a negative one, and Dn a negative type to a positive one, standing for the same object: a term of Dn n is a stored term of n.

Constructors

I 
(SYN k) :** (SYN k) infixl 7 
(SYN k) :-> (SYN k) infixr 5 
(SYN k) :&& (SYN k) infixl 6 
Top 
(SYN k) :|| (SYN k) infixl 6 
Zero 

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 #

(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 #

(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 #

(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 #

(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 #

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 #

(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 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 => 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 #

(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 #

(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, 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 #

(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, 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 #

(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 #

(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 #

(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 #

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 F (a :: k) = 'F ('PR a) Source Github #

A base-category object in the SMC syntax over PROD k.

type Interp (a :: SYN (PROD k)) = UN ('PR :: k -> PROD k) (Interp a) Source Github #

The base-category object a cartesian type expression stands for.

class CategoryOf k => KnownObj (s :: SYN k) Source Github #

Type expressions whose Interp is an object, given that their leaves are.

Minimal complete definition

withSynOb

Instances

Instances details
Monoidal k => KnownObj ('I :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Syntax

Methods

withSynOb :: (Ob (Interp ('I :: SYN k)) => r) -> r Source Github #

HasTerminalObject k => KnownObj ('Top :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Syntax

Methods

withSynOb :: (Ob (Interp ('Top :: SYN k)) => r) -> r Source Github #

HasInitialObject k => KnownObj ('Zero :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Syntax

Methods

withSynOb :: (Ob (Interp ('Zero :: SYN k)) => r) -> r Source Github #

KnownObj a => KnownObj ('Dn a :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Syntax

Methods

withSynOb :: (Ob (Interp ('Dn a)) => r) -> r Source Github #

(CategoryOf k, Ob a) => KnownObj ('F a :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Syntax

Methods

withSynOb :: (Ob (Interp ('F a)) => r) -> r Source Github #

(Dialogue k, KnownObj a) => KnownObj ('Not a :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Syntax

Methods

withSynOb :: (Ob (Interp ('Not a)) => r) -> r Source Github #

(HasBinaryProducts k, KnownObj a, KnownObj b) => KnownObj (a ':&& b :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Syntax

Methods

withSynOb :: (Ob (Interp (a ':&& b)) => r) -> r Source Github #

(Monoidal k, KnownObj a, KnownObj b) => KnownObj (a ':** b :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Syntax

Methods

withSynOb :: (Ob (Interp (a ':** b)) => r) -> r Source Github #

(Closed k, KnownObj a, KnownObj b) => KnownObj (a ':-> b :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Syntax

Methods

withSynOb :: (Ob (Interp (a ':-> b)) => r) -> r Source Github #

(HasBinaryCoproducts k, KnownObj a, KnownObj b) => KnownObj (a ':|| b :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Syntax

Methods

withSynOb :: (Ob (Interp (a ':|| b)) => r) -> r Source Github #

Terms

Products

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 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.

Minimal complete definition

toTerm

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 #

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

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

toCCC :: forall {k} (a :: SYN (PROD k)) (b :: SYN (PROD k)) t cont. (HasProducts k, Binds ((~>) :: CAT (PROD k)) 0 ('[] :: [(Nat, SYN (PROD k))]) a b t cont) => (t -> cont) -> Interp a ~> Interp b Source Github #

Compile a function on terms into an arrow of k. The input arrives through an SMC pattern, a variable, (), or a tuple, and the body's operations determine the additional structure needed.

toCCC1 :: forall {k} (a :: k) (b :: k) t cont. (HasProducts k, Binds ((~>) :: CAT (PROD k)) 0 ('[] :: [(Nat, SYN (PROD k))]) (F a) (F b) t cont) => (t -> cont) -> a ~> b Source Github #

toCCC with both boundary objects embedded by F. The surrounding morphism type determines the input and output objects, so their type applications can be omitted. Use toCCC when a boundary needs other syntax, such as a product or function type.

lift :: forall {k} (a :: SYN (PROD k)) (b :: SYN (PROD k)) (d :: Nat) (g :: Ctx (PROD k)) t. (CategoryOf k, Is ('PR :: k -> PROD k) (Interp a), Is ('PR :: k -> PROD k) (Interp b), ToTerm (Hom (PROD k)) t d g a) => (Interp a ~> Interp b) -> t -> Term d g b Source Github #

Lift a base-category arrow onto terms. The type expressions can be composite, as in SMC's lift; use type applications when their interpretations do not determine them.

liftF :: forall {k} (a :: SYN (PROD k)) (b :: k) t (d :: Nat) (g :: Ctx (PROD k)). (CategoryOf k, Is ('PR :: k -> PROD k) (Interp a), BuildTuple (Hom (PROD k)) t g a) => (Interp a ~> b) -> t -> Term d g (F b) Source Github #

Lift a base-category arrow onto a term or tuple of terms, embedding its result by F. The result object is inferred from the arrow. Use lift for composite result syntax.

(-<) :: forall {k} (a :: SYN (PROD k)) (b :: k) t (d :: Nat) (g :: Ctx (PROD k)). (CategoryOf k, Is ('PR :: k -> PROD k) (Interp a), BuildTuple (Hom (PROD k)) t g a) => (Interp a ~> b) -> t -> Term d g (F b) infixr 0 Source Github #

Arrow application, mirroring f -< x in Haskell's arrow notation. This is infix liftF: the input may be a term or tuple, and the result is embedded by F. The Arrows extension must be disabled, since it reserves this symbol.

returnA :: forall {k} p (a :: k). (Promonad p, Ob a) => p a a Source Github #

The identity morphism, named as in Haskell's arrow notation. An alias for id; returnA -< x embeds the input by F.

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.

(**) :: 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.

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.

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 Up a is the computation of the pair at a. 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) 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.

Minimal complete definition

tuple

Instances

Instances details
(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.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Pattern

Methods

tuple :: forall (d :: Nat). () -> TermP p d g a Source Github #

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.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Pattern

Methods

tuple :: forall (d :: Nat). t -> TermP p d g a Source Github #

(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.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Pattern

Methods

tuple :: forall (d :: Nat). (x, y) -> TermP p d g a Source Github #

(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.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Pattern

Methods

tuple :: forall (d :: Nat). (x, y) -> TermP p d g ('Not ('Not a)) Source Github #

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

Defined in Proarrow.Tools.SMC.Internal.Pattern

Methods

tuple :: forall (d :: Nat). (x, y, z) -> TermP p d g a 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 # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Pattern

Methods

tuple :: forall (d :: Nat). (w, x, y, z) -> TermP p d g a 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 # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Pattern

Methods

tuple :: forall (d :: Nat). (v, w, x, y, z) -> TermP p d g a 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 # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Pattern

Methods

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

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.

with :: forall {k} (a :: SYN k) (b :: SYN k) (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k). (HasBinaryProducts k, Thin (Union g1 g2) g1, Thin (Union g1 g2) g2) => Term d g1 a -> Term d g2 b -> Term d (Union g1 g2) (a ':&& b) Source Github #

Both of two alternatives over the same variables: the product. This needs products.

exl :: forall {k} {p :: k +-> k} (a :: SYN k) (b :: SYN k) (d :: Nat) (g :: Ctx k). (HasBinaryProducts k, Profunctor p, KnownObj a, KnownObj b) => TermP p d g (a ':&& b) -> TermP p d g a Source Github #

The first alternative of a product.

exr :: forall {k} {p :: k +-> k} (a :: SYN k) (b :: SYN k) (d :: Nat) (g :: Ctx k). (HasBinaryProducts k, Profunctor p, KnownObj a, KnownObj b) => TermP p d g (a ':&& b) -> TermP p d g b Source Github #

The second alternative of a product.

absorb :: forall {k} {p :: k +-> k} (s :: SYN k) (d :: Nat) (g :: Ctx k). (HasTerminalObject k, Profunctor p, KnownObj s) => TermP p d g s -> TermP p d g ('Top :: SYN k) Source Github #

Use up a term into the unit of the product.

Product exponentials

lam :: forall {k} (d :: Nat) (r :: Ctx k) (a :: SYN k) (b :: SYN k) t cont. (Closed k, Binds ((~>) :: CAT k) d r a b t cont) => (t -> cont) -> Term d r (a ':-> b) Source Github #

A function: the body receives the argument through a pattern (see Patterns). This needs the category to be closed.

class Apply (p :: CAT k) f x r | f -> p where Source Github #

Function application. A variable both the function and its argument use is copied. Explicit exponentials determine their result syntax. Embedded function objects, such as results of (-<), take their result syntax from the surrounding term.

Methods

(!) :: f -> x -> r infixl 8 Source Github #

Instances

Instances details
(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 #

Coproducts

inl :: forall {k} (a :: SYN k) (b :: SYN k) (d :: Nat) (g :: Ctx k) (p :: k +-> k). (Profunctor p, HasBinaryCoproducts k, KnownObj a, KnownObj b) => TermP p d g a -> TermP p d g (a ':|| b) Source Github #

The left injection into a coproduct.

inr :: forall {k} (a :: SYN k) (b :: SYN k) (d :: Nat) (g :: Ctx k) (p :: k +-> k). (Profunctor p, HasBinaryCoproducts k, KnownObj a, KnownObj b) => TermP p d g b -> TermP p d g (a ':|| b) Source Github #

The right injection into a coproduct.

caseOf :: forall {k} (a :: SYN k) (b :: SYN k) (c :: SYN k) (d :: Nat) (g :: Ctx k) (r1 :: Ctx k) (r2 :: Ctx k) t1 cont1 t2 cont2 (s :: SYN k) (p :: CAT k). (Distributive k, Promonad p, DistributiveProfunctor p, Sum s a b, KnownObj a, KnownObj b, Binds p d r1 a c t1 cont1, Binds p d r2 b c t2 cont2, Thin (Union r1 r2) r1, Thin (Union r1 r2) r2, Merge (Union r1 r2) g) => TermP p d g s -> (t1 -> cont1) -> (t2 -> cont2) -> TermP p d (Union (Union r1 r2) g) c Source Github #

Case analysis on a coproduct. Each branch receives the contents of its alternative through a pattern (see Patterns), and the variables of the term around it are shared between the branches. This needs the tensor to distribute over the coproduct. The sum may be written with (:||) or embedded by F, as in the result of (-<). For Arr, this needs ArrowChoice and runs only the selected branch.

ifThenElse :: forall {k} (a :: SYN k) (b :: SYN k) (c :: SYN k) (d :: Nat) (g :: Ctx k) (r1 :: Ctx k) (r2 :: Ctx k) t1 cont1 t2 cont2 (s :: SYN k) (p :: CAT k). (Distributive k, Promonad p, DistributiveProfunctor p, Sum s a b, KnownObj a, KnownObj b, Binds p d r1 a c t1 cont1, Binds p d r2 b c t2 cont2, Thin (Union r1 r2) r1, Thin (Union r1 r2) r2, Merge (Union r1 r2) g) => TermP p d g s -> (t1 -> cont1) -> (t2 -> cont2) -> TermP p d (Union (Union r1 r2) g) c Source Github #

caseOf as overloaded if syntax with RebindableSyntax. Import ifThenElse unqualified and write if x then l -> ... else r -> .... The then branch handles the left alternative and the else branch handles the right; each receives its payload.

class Interp s ~ Interp (a ':|| b) => Sum (s :: SYN k) (a :: SYN k) (b :: SYN k) Source Github #

A sum with components a and b: either a :|| b or a coproduct embedded by F.

Instances

Instances details
s ~ (a ':|| b) => Sum (s :: SYN k) (a :: SYN k) (b :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Additive

(z ~ (x || y), a ~ 'F x, b ~ 'F y) => Sum ('F z :: SYN k) (a :: SYN k) (b :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Additive

absurd :: forall {k} {p :: k +-> k} (s :: SYN k) (c :: SYN k) (d :: Nat) (g1 :: Ctx k) (g2 :: Ctx k). (Distributive k, MonoidalProfunctor p, KnownObj s, KnownObj c, Merge g1 g2) => TermP p d g1 s -> TermP p d g2 ('Zero :: SYN k) -> TermP p d (Union g1 g2) c Source Github #

There is no term of Zero, so from one, together with the rest of the context, anything follows.

Contexts

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

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

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

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

Minimal complete definition

ctxCase, withCtxOb

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 #

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) 

class (KnownCtx g1, KnownCtx g2) => Merge (g1 :: Ctx k) (g2 :: Ctx k) 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.

Minimal complete definition

merge

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 g, KnownCtx h) => Thin (g :: Ctx k) (h :: Ctx k) 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.

Minimal complete definition

thin

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 r => BindVar (n :: Nat) (a :: SYN k) (g :: Ctx k) (r :: Ctx k) | n g -> r 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.

Minimal complete definition

bindVar

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 #

Do notation

(>>=) :: Bind p m t cont r => m -> (t -> cont) -> r Source Github #

Bind the right hand side to the pattern of the continuation.

return :: forall k t (d :: Nat) (p :: CAT k). (Monoidal k, Promonad p, RecVars k t, KnownCtx (Vars k t)) => t -> Ret t (TermP p d (Vars k t) (Mul (Vars k t))) Source Github #

The end of a rec block: all its variables, as the tensor of their context.

fail :: a Source Github #

GHC's translation of rec refers to fail, but pairs of variables always match.

class Bind (p :: CAT k) m t cont r | m -> p Source Github #

A bind in a do block: a term, constant or tuple taken apart by a pattern, or the variables of a rec block.

Minimal complete definition

(>>=)

Instances

Instances details
(TupleProfunctor '[x, y] p, ToTerm p (x, y) d g a, Bind p (TermP p d g a) t cont r) => Bind (p :: CAT k) (x, y) t cont r Source Github #

Convert a tuple before binding it. At least one component must identify the promonad.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

(>>=) :: (x, y) -> (t -> cont) -> r Source Github #

(p ~ q, a ~ (Unit :: k), Bind p (TermP p d ('[] :: [(Nat, SYN k)]) ('F b)) t cont r) => Bind (p :: CAT k) (q a b) t cont r Source Github #

Bind a constant arrow, computing it once before the continuation.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

(>>=) :: q a b -> (t -> cont) -> r Source Github #

Bind p ((x, y), z) t cont r => Bind (p :: CAT k) (x, y, z) t cont r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

(>>=) :: (x, y, z) -> (t -> cont) -> r Source Github #

Bind p ((w, x, y), z) t cont r => Bind (p :: CAT k) (w, x, y, z) t cont r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

(>>=) :: (w, x, y, z) -> (t -> cont) -> r Source Github #

(Promonad p, MonoidalProfunctor p, Costrong (Tensor :: k -> (k, k) -> Type) p, SymMonoidal k, RecVars k t, AnyDepth t t', AnyDepth t' t, RecVars k t', ToTerm p cont (RecDepth d (Vars k t)) gc c, r ~ TermP p d (Union (Minus gc (Vars k t)) (Minus g (Vars k t))) c, Unmerge (Inter g (Vars k t)) (Minus g (Vars k t)), Union (Inter g (Vars k t)) (Minus g (Vars k t)) ~ g, Thin (Vars k t) (Union (Inter g (Vars k t)) (Inter gc (Vars k t))), Merge (Inter g (Vars k t)) (Inter gc (Vars k t)), Merge (Minus gc (Vars k t)) (Minus g (Vars k t)), Unmerge (Minus gc (Vars k t)) (Inter gc (Vars k t)), Union (Minus gc (Vars k t)) (Inter gc (Vars k t)) ~ gc) => Bind (p :: CAT k) (Rec p d t g) t' cont r Source Github #

The rest of the do block after a rec block, which traces it. The variables of the block that the block itself uses are fed back, the ones the rest uses are passed on, a variable that both use is copied, and one that neither uses is discarded. The rest gets the variables anew, with the same ids, so that it can use them at its own depth.

Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

(>>=) :: Rec p d t g -> (t' -> cont) -> 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 #

Bind p ((v, w, x, y), z) t cont r => Bind (p :: CAT k) (v, w, x, y, z) t cont r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

(>>=) :: (v, w, x, y, z) -> (t -> cont) -> r 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 #

Bind p ((u, v, w, x, y), z) t cont r => Bind (p :: CAT k) (u, v, w, x, y, z) t cont r Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Methods

(>>=) :: (u, v, w, x, y, z) -> (t -> cont) -> r Source Github #

class (KnownObj a, KnownCtx g) => Binds (p :: CAT k) (n :: Nat) (g :: Ctx k) (a :: SYN k) (b :: SYN k) t cont 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.

Minimal complete definition

bound

Instances

Instances details
(Promonad p, KnownObj a, KnownCtx g, BindPat p (TermP p (n + 1) '['(n, a)] a) t cont (TermP p (n + 1) g' b), BindVar n a g' g) => Binds (p :: CAT k) n (g :: Ctx k) (a :: SYN k) (b :: SYN k) t cont Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Pattern

Methods

bound :: (t -> cont) -> p (Interp (Mul g) ** Interp a) (Interp b) Source Github #

Examples

injectRight :: forall {k} (a :: k) (b :: k). (HasProducts k, HasBinaryCoproducts k, Ob a, Ob b) => a ~> (b || a) Source Github #

Inject as the right element of a sum.

>>> import Prelude (Bool (..))
>>> injectRight @Bool @Bool True
Right True

swapProduct :: forall {k} (a :: k) (b :: k). (HasProducts k, Ob a, Ob b) => (a && b) ~> (b && a) Source Github #

Swap a product. Only products are needed.

>>> import Prelude (Bool (..))
>>> swapProduct @Bool @Bool (True, False)
(False,True)

applyPair :: forall {k} (a :: k) (b :: k). (HasProducts k, Closed (PROD k), Ob a, Ob b) => Interp ((F a ':-> F b) ':** F a) ~> b Source Github #

Apply a function to an argument, both bundled in a product.

>>> import Prelude (Bool (..), not)
>>> applyPair @Bool @Bool (not, True)
False

curryPair :: forall {k} (a :: k) (b :: k). (HasProducts k, Closed (PROD k), Ob a, Ob b) => a ~> Interp (F b ':-> (F a ':** F b)) Source Github #

Curry a pairing function.

>>> import Prelude (Bool (..))
>>> curryPair @Bool @Bool True False
(True,False)

flipCurried3 :: forall {k} (a :: k) (b :: k) (c :: k). (HasProducts k, Closed (PROD k), Ob a, Ob b, Ob c) => Interp (F b ':-> (F a ':-> (F b ':-> F c))) ~> Interp (F a ':-> (F b ':-> F c)) Source Github #

Flip the first two arguments of a curried function, supplying its third argument from the second as well. Nested binders and a repeated variable use SMC's contexts.

>>> import Prelude (Bool (..))
>>> flipCurried3 @Bool @Bool @Bool (\_ a _ -> a) True False
True

swapSum :: forall {k} (a :: k) (b :: k). (HasProducts k, Distributive (PROD k), Ob a, Ob b) => (a || b) ~> (b || a) Source Github #

Swap a sum by case analysis. No exponentials are needed.

>>> import Prelude (Bool (..), Either (..))
>>> swapSum @Bool @Bool (Left True)
Right True
>>> swapSum @Bool @Bool (Right False)
Left False

caseEither :: forall {k} (a :: k) (b :: k) (c :: k). (HasProducts k, Closed (PROD k), Distributive (PROD k), Ob a, Ob b, Ob c) => Interp ((F a ':|| F b) ':** ((F a ':-> F c) ':** (F b ':-> F c))) ~> c Source Github #

Apply whichever function matches the branch of a sum. The functions are shared with the selected branch through the context.

>>> import Prelude (Bool (..), Either (..), id, not)
>>> caseEither @Bool @Bool @Bool (Left True, (not, id))
False
>>> caseEither @Bool @Bool @Bool (Right True, (not, id))
True