proarrow
Safe HaskellNone
LanguageGHC2024

Proarrow.Tools.SMC.Internal.Do

Description

Internal module of Proarrow.Tools.SMC: do notation, including rec blocks. It exports everything, also what the public module keeps hidden.

Synopsis

Documentation

class Bind (p :: CAT k) m t cont r | m -> p where 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.

Methods

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

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

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 TupleProfunctor (ts :: [Type]) (p :: CAT k) | ts -> p Source Github #

Instances

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

Defined in Proarrow.Tools.SMC.Internal.Do

TupleProfunctor (x ': (y ': ts)) p => TupleProfunctor ((x, y) ': ts) (p :: CAT k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

TupleProfunctor (((x, y), z) ': ts) p => TupleProfunctor ((x, y, z) ': ts) (p :: CAT k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

TupleProfunctor (((w, x, y), z) ': ts) p => TupleProfunctor ((w, x, y, z) ': ts) (p :: CAT k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

TupleProfunctor (((v, w, x, y), z) ': ts) p => TupleProfunctor ((v, w, x, y, z) ': ts) (p :: CAT k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

TupleProfunctor (((u, v, w, x, y), z) ': ts) p => TupleProfunctor ((u, v, w, x, y, z) ': ts) (p :: CAT k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

TupleProfunctor ts p => TupleProfunctor (() ': ts) (p :: CAT k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

p ~ q => TupleProfunctor (q a b ': ts) (p :: k -> k -> Type) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

class BindTerm (p :: CAT k) t m cont r where Source Github #

A bind of a term, by its pattern. A variable pattern binds a new variable, so that the right hand side is computed once however often the variable is used. The other patterns take the right hand side apart into new variables already.

Methods

bindTerm :: m -> (t -> cont) -> r Source Github #

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 #

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 #

class Interp c ~ Dual (Interp y) => Negative (c :: SYN k) (y :: SYN k) Source Github #

Instances

Instances details
f ~ Dual (Interp y) => Negative ('F f :: SYN k) (y :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

y ~ y' => Negative ('Not y' :: SYN k) (y :: SYN k) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

newtype Ret t x Source Github #

The body of a rec block, tagged with the tuple of its variables. GHC's translation passes that tuple to both return and mfix, and this tag is what makes them the same.

Constructors

Ret x 

Instances

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

unRet :: Ret t x -> x Source Github #

class RecVars k t where Source Github #

The variables of a rec block, as GHC tuples them up.

Associated Types

type Vars k t :: Ctx k Source Github #

Methods

recVars :: t Source Github #

Instances

Instances details
RecVars k () Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Associated Types

type Vars k () 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

type Vars k () = '[] :: [(Nat, SYN k)]

Methods

recVars :: () Source Github #

(RecVars k x, RecVars k y) => RecVars k (x, y) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Associated Types

type Vars k (x, y) 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

type Vars k (x, y) = Union (Vars k x) (Vars k y)

Methods

recVars :: (x, y) Source Github #

(RecVars k x, RecVars k y, RecVars k z) => RecVars k (x, y, z) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Associated Types

type Vars k (x, y, z) 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

type Vars k (x, y, z) = Union (Vars k x) (Vars k (y, z))

Methods

recVars :: (x, y, z) Source Github #

(RecVars k x, RecVars k y, RecVars k z, RecVars k w) => RecVars k (x, y, z, w) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Associated Types

type Vars k (x, y, z, w) 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

type Vars k (x, y, z, w) = Union (Vars k x) (Vars k (y, z, w))

Methods

recVars :: (x, y, z, w) 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 #

(RecVars k x, RecVars k y, RecVars k z, RecVars k w, RecVars k v) => RecVars k (x, y, z, w, v) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Associated Types

type Vars k (x, y, z, w, v) 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

type Vars k (x, y, z, w, v) = Union (Vars k x) (Vars k (y, z, w, v))

Methods

recVars :: (x, y, z, w, v) Source Github #

(RecVars k x, RecVars k y, RecVars k z, RecVars k w, RecVars k v, RecVars k u) => RecVars k (x, y, z, w, v, u) Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

Associated Types

type Vars k (x, y, z, w, v, u) 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

type Vars k (x, y, z, w, v, u) = Union (Vars k x) (Vars k (y, z, w, v, u))

Methods

recVars :: (x, y, z, w, v, u) Source Github #

class AnyDepth t t' Source Github #

The variables of a rec block again, at a depth of their own: the rest of the block uses them deeper than the block did. It is asked for both ways, so that what is known about the variables on either side of the block determines the other.

Instances

Instances details
t' ~ () => AnyDepth () t' Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

(AnyDepth x x', AnyDepth y y', t' ~ (x', y')) => AnyDepth (x, y) t' Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

(AnyDepth x x', AnyDepth y y', AnyDepth z z', t' ~ (x', y', z')) => AnyDepth (x, y, z) t' Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

(AnyDepth x x', AnyDepth y y', AnyDepth z z', AnyDepth w w', t' ~ (x', y', z', w')) => AnyDepth (x, y, z, w) t' Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

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

Defined in Proarrow.Tools.SMC.Internal.Do

(AnyDepth x x', AnyDepth y y', AnyDepth z z', AnyDepth w w', AnyDepth v v', t' ~ (x', y', z', w', v')) => AnyDepth (x, y, z, w, v) t' Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

(AnyDepth x x', AnyDepth y y', AnyDepth z z', AnyDepth w w', AnyDepth v v', AnyDepth u u', t' ~ (x', y', z', w', v', u')) => AnyDepth (x, y, z, w, v, u) t' Source Github # 
Instance details

Defined in Proarrow.Tools.SMC.Internal.Do

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.

data Rec (p :: CAT k) (d :: Nat) t (g :: Ctx k) where Source Github #

A rec block before tracing: its body, from its context g to all its variables. Which of them are fed back and which are passed on is only known with the rest of the block, see the Bind instance.

Constructors

Rec :: forall {k} (p :: CAT k) (d :: Nat) t (g :: Ctx k). p (Interp (Mul g)) (Interp (Mul (Vars k t))) -> Rec p d t g 

Instances

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

mfix :: forall {k} t (d :: Nat) (g :: Ctx k) (p :: CAT k). RecVars k t => (t -> Ret t (TermP p d g (Mul (Vars k t)))) -> Rec p d t g Source Github #

The body of a rec block, to be traced by the bind after it.

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

Equations

RecDepth d ('[] :: [(Nat, SYN k)]) = d 
RecDepth d ('(n, a) ': g :: [(Nat, SYN k)]) = n + 1 

fail :: a Source Github #

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