| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
SysL
Description
System L with polynomial types and These covariable boundaries.
This module rebuilds the original hand-rolled Loop (,) (->) interpreter
as a circuits client:
- User-facing types are promoted to
Polypolynomials viaSysLTy. - Command results are expressed with
Theseboundaries, matching the inclusive tensor in Circuit.Channel. - The syntactic target is the free SMC
SMC (->); boundaries useTheseat the value level. - A streaming reading is provided via
Process.
The original four regression tests are preserved as testId, testThen,
testIdLoop and testThenLoop.
Synopsis
- data Ty
- type family SysLTy (t :: Ty) :: Poly where ...
- type family Domain (t :: Ty) where ...
- data Val v
- type Output v = (Int, Val v)
- type Result v = These (Output v) (Output v)
- type Env v = [Val v]
- data Command v = Cut (Term v) (Coterm v)
- data Value v
- = Var Int
- | TensorIntro (Value v) (Value v)
- | PlusIntroL (Value v)
- | PlusIntroR (Value v)
- | HomComatch (Command v)
- | GradedHomComatch (Command v)
- | Lit (Val v)
- data Term v
- data Coterm v
- = Covar Int
- | Comu (Command v)
- | TensorMatch (Command v)
- | PlusMatch (Command v) (Command v)
- | HomCointro (Term v) (Coterm v)
- | GradedHomCointro (Term v) [Coterm v]
- | ThenCointro (Coterm v) (Coterm v)
- evalCommand :: Command v -> Env v -> Result v
- evalValue :: Value v -> Env v -> Val v
- evalTerm :: Term v -> Env v -> These (Output v) (Val v)
- evalCoterm :: Coterm v -> Env v -> Val v -> Result v
- lookupEnv :: Int -> Env v -> Val v
- class PolyVal (t :: Ty) where
- type SMCThese = SMC (,) (->)
- commandToSMC :: Command v -> SMCThese (Env v) (Result v)
- termToSMC :: Term v -> SMCThese (Env v) (These (Output v) (Val v))
- cotermToSMC :: Coterm v -> SMCThese (Env v, Val v) (Result v)
- evalProcess :: Term v -> Process (Env v) (Val v)
- thenLens :: (Val v -> Val v) -> (Val v -> Val v -> Val v) -> Morphism (Mono (Val v) (Val v)) (Mono (Val v) (Val v))
- applyThen :: Morphism (Mono (Val v) (Val v)) (Mono (Val v) (Val v)) -> Val v -> (Val v, Val v -> Val v)
- testId :: Result ()
- testThen :: Result Double
- testIdLoop :: Result ()
- testThenLoop :: Result Double
Types
User-facing SysL type syntax.
Values and boundaries
Runtime values, parametric in the opaque domain type v.
type Result v = These (Output v) (Output v) Source #
A result is now a covariable boundary using the inclusive These tensor.
Thiscarries a residual output (slot >= 1).Thatcarries a focus output (slot 0).Thesecarries both residual and focus.
This follows the convention in Circuit.Channel: This is the
feedback residual branch and That is the payload focus branch.
Syntax
Constructors
| Var Int | |
| TensorIntro (Value v) (Value v) | |
| PlusIntroL (Value v) | |
| PlusIntroR (Value v) | |
| HomComatch (Command v) | |
| GradedHomComatch (Command v) | |
| Lit (Val v) |
Constructors
| Covar Int | |
| Comu (Command v) | |
| TensorMatch (Command v) | |
| PlusMatch (Command v) (Command v) | |
| HomCointro (Term v) (Coterm v) | |
| GradedHomCointro (Term v) [Coterm v] | |
| ThenCointro (Coterm v) (Coterm v) |
Direct evaluator
Polynomial view
class PolyVal (t :: Ty) where Source #
Convert between the runtime Val representation and the polynomial
Eval representation for a closed SysL type.
SMC SMC compiler
type SMCThese = SMC (,) (->) Source #
Type synonym for the free symmetric monoidal target.
SMC (->) is the free SMC over plain functions. Boundaries are still
expressed with These at the value level, but the free category itself
uses the cartesian (,) tensor for SMCPar wiring rather than the
inclusive These tensor. This avoids the impossibility of a Traced
instance for These.
Process interpreter
evalProcess :: Term v -> Process (Env v) (Val v) Source #
Streaming interpreter: each input is a fresh environment, each output is the focus value of the term. Residual escape is a run-time error, which is the expected behaviour for a closed term consumed by a process.
Then as optic
thenLens :: (Val v -> Val v) -> (Val v -> Val v -> Val v) -> Morphism (Mono (Val v) (Val v)) (Mono (Val v) (Val v)) Source #
applyThen :: Morphism (Mono (Val v) (Val v)) (Mono (Val v) (Val v)) -> Val v -> (Val v, Val v -> Val v) Source #
Apply a Then lens to an input value, returning the forward output and
the backward continuation.
Regression tests
testIdLoop :: Result () Source #
Identity test compiled to SMC.
testThenLoop :: Result Double Source #
Then test compiled to SMC.