Documentation
¶
Overview ¶
Package typed is the no-any checked core for expression programs. Parsing may return SomeExpr, but after its exhaustive match every expression and evaluation result has a concrete Go type.
Index ¶
- func DepthFold[R any](d Depth, cs DepthCases[R]) R
- func EffectEqual(a, b Effect) bool
- func EffectEqualWith(a, b Effect, ov EffectEqOverrides) bool
- func EffectFold[R any](e Effect, cs EffectCases[R]) R
- func EvalResultFold[T any, R any](e EvalResult[T], cs EvalResultCases[T, R]) R
- func ExprFold[T any, R any](e Expr[T], cs ExprCases[T, R]) R
- func InstructionFold[R any](i Instruction, cs InstructionCases[R]) R
- func IntegerOperationEqual(a, b IntegerOperation) bool
- func IntegerOperationEqualWith(a, b IntegerOperation, ov IntegerOperationEqOverrides) bool
- func IntegerOperationFold[R any](i IntegerOperation, cs IntegerOperationCases[R]) R
- func PopStack(stack Stack) (Value, Stack)
- func SomeExprEqual(a, b SomeExpr) bool
- func SomeExprEqualWith(a, b SomeExpr, ov SomeExprEqOverrides) bool
- func SomeExprFold[R any](s SomeExpr, cs SomeExprCases[R]) R
- func ValueEqual(a, b Value) bool
- func ValueEqualWith(a, b Value, ov ValueEqOverrides) bool
- func ValueFold[R any](v Value, cs ValueCases[R]) R
- type Add
- type AddOperation
- type And
- type Bool
- type BoolValue
- type BoolVariable
- type Depth
- type DepthCases
- type Divide
- type DivideOperation
- type Effect
- type EffectCases
- type EffectEqOverrides
- type Environment
- type EqualBool
- type EqualInt
- type EqualString
- type EvalResult
- func AddIntegers(stack Stack) EvalResult[Stack]
- func Eval[T any](expression Expr[T], environment Environment) EvalResult[T]
- func ExecuteGrowthInstruction(instruction Instruction, stack Stack, environment Environment) EvalResult[Stack]
- func ExecuteIntegerInstruction(instruction Instruction, stack Stack) EvalResult[Stack]
- func ExecuteIntegerProgram(left, right int) EvalResult[Stack]
- type EvalResultCases
- type Evaluated
- type Expr
- type ExprCases
- type Greater
- type GreaterEqual
- type If
- type Instruction
- type InstructionCases
- type Int
- type IntValue
- type IntVariable
- type IntegerAdd
- type IntegerDivide
- type IntegerModulo
- type IntegerMultiply
- type IntegerOperation
- type IntegerOperationCases
- type IntegerOperationEqOverrides
- type IntegerSubtract
- type Less
- type LessEqual
- type LoadInteger
- type Modulo
- type ModuloOperation
- type Multiply
- type MultiplyOperation
- type Negate
- type NextDepth
- type Not
- type Or
- type Pure
- type Push
- type ReadsEnvironment
- type RuntimeError
- type RuntimeFailed
- type SomeBool
- type SomeExpr
- type SomeExprCases
- type SomeExprEqOverrides
- type SomeInt
- type SomeString
- type Stack
- type String
- type StringValue
- type StringVariable
- type Subtract
- type SubtractOperation
- type Value
- type ValueCases
- type ValueEqOverrides
- type ZeroDepth
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DepthFold ¶
func DepthFold[R any](d Depth, cs DepthCases[R]) R
DepthFold reduces Depth by one-level case analysis.
func EffectEqual ¶
EffectEqual reports structural equality of a and b.
func EffectEqualWith ¶
func EffectEqualWith(a, b Effect, ov EffectEqOverrides) bool
EffectEqualWith reports structural equality of a and b under ov.
func EffectFold ¶
func EffectFold[R any](e Effect, cs EffectCases[R]) R
EffectFold reduces Effect by one-level case analysis.
func EvalResultFold ¶
func EvalResultFold[T any, R any](e EvalResult[T], cs EvalResultCases[T, R]) R
EvalResultFold reduces EvalResult[T] by one-level case analysis.
func InstructionFold ¶
func InstructionFold[R any](i Instruction, cs InstructionCases[R]) R
InstructionFold reduces Instruction by one-level case analysis.
func IntegerOperationEqual ¶
func IntegerOperationEqual(a, b IntegerOperation) bool
IntegerOperationEqual reports structural equality of a and b.
func IntegerOperationEqualWith ¶
func IntegerOperationEqualWith(a, b IntegerOperation, ov IntegerOperationEqOverrides) bool
IntegerOperationEqualWith reports structural equality of a and b under ov.
func IntegerOperationFold ¶
func IntegerOperationFold[R any](i IntegerOperation, cs IntegerOperationCases[R]) R
IntegerOperationFold reduces IntegerOperation by one-level case analysis.
func SomeExprEqual ¶
SomeExprEqual reports structural equality of a and b.
func SomeExprEqualWith ¶
func SomeExprEqualWith(a, b SomeExpr, ov SomeExprEqOverrides) bool
SomeExprEqualWith reports structural equality of a and b under ov.
func SomeExprFold ¶
func SomeExprFold[R any](s SomeExpr, cs SomeExprCases[R]) R
SomeExprFold reduces SomeExpr by one-level case analysis.
func ValueEqual ¶
ValueEqual reports structural equality of a and b.
func ValueEqualWith ¶
func ValueEqualWith(a, b Value, ov ValueEqOverrides) bool
ValueEqualWith reports structural equality of a and b under ov.
func ValueFold ¶
func ValueFold[R any](v Value, cs ValueCases[R]) R
ValueFold reduces Value by one-level case analysis.
Types ¶
type AddOperation ¶
type AddOperation struct{}
type BoolVariable ¶
type BoolVariable struct {
Name string
}
type Depth ¶
type Depth interface {
// contains filtered or unexported methods
}
Depth and Stack make underflow unrepresentable in Go+.
type DepthCases ¶
DepthCases selects one handler per Depth variant for DepthFold.
type DivideOperation ¶
type DivideOperation struct{}
type EffectCases ¶
type EffectCases[R any] struct { Pure func() R ReadsEnvironment func() R }
EffectCases selects one handler per Effect variant for EffectFold.
type EffectEqOverrides ¶
type EffectEqOverrides struct {
Pure func(x, y Pure) (eq, handled bool)
ReadsEnvironment func(x, y ReadsEnvironment) (eq, handled bool)
}
EffectEqOverrides carries optional per-variant hooks for EffectEqualWith. A hook returning handled=false falls through to the derived comparison.
type Environment ¶
type EvalResult ¶
type EvalResult[T any] interface { // contains filtered or unexported methods }
func AddIntegers ¶
func AddIntegers(stack Stack) EvalResult[Stack]
AddIntegers is an executable n+2 -> n+1 transition. Stack underflow is unrepresentable; a wrong runtime value kind remains an explicit failure at the erased ordinary-Go boundary.
func Eval ¶
func Eval[T any](expression Expr[T], environment Environment) EvalResult[T]
func ExecuteGrowthInstruction ¶
func ExecuteGrowthInstruction(instruction Instruction, stack Stack, environment Environment) EvalResult[Stack]
ExecuteGrowthInstruction exhaustively interprets every n -> n+1 instruction. Arithmetic constructors cannot inhabit this stack effect and are eliminated by GADT refinement.
func ExecuteIntegerInstruction ¶
func ExecuteIntegerInstruction(instruction Instruction, stack Stack) EvalResult[Stack]
ExecuteIntegerInstruction exhaustively interprets every n+2 -> n+1 arithmetic instruction. Growth constructors cannot inhabit this effect.
func ExecuteIntegerProgram ¶
func ExecuteIntegerProgram(left, right int) EvalResult[Stack]
ExecuteIntegerProgram demonstrates composition of verified bytecode stack effects: 0 -> 1 -> 2 -> 1. Changing or omitting either push is rejected by the dependent checker before Go generation.
type EvalResultCases ¶
type EvalResultCases[T any, R any] struct { Evaluated func(Value T) R RuntimeFailed func(Error RuntimeError) R }
EvalResultCases selects one handler per EvalResult variant for EvalResultFold.
type ExprCases ¶
type ExprCases[T any, R any] struct { Int func(value int) R Bool func(value bool) R String func(value string) R IntVariable func(name string) R BoolVariable func(name string) R StringVariable func(name string) R Negate func(value Expr[int]) R Not func(value Expr[bool]) R Add func(left Expr[int], right Expr[int]) R Subtract func(left Expr[int], right Expr[int]) R Multiply func(left Expr[int], right Expr[int]) R Divide func(left Expr[int], right Expr[int]) R Modulo func(left Expr[int], right Expr[int]) R Less func(left Expr[int], right Expr[int]) R LessEqual func(left Expr[int], right Expr[int]) R Greater func(left Expr[int], right Expr[int]) R GreaterEqual func(left Expr[int], right Expr[int]) R EqualInt func(left Expr[int], right Expr[int]) R EqualBool func(left Expr[bool], right Expr[bool]) R EqualString func(left Expr[string], right Expr[string]) R And func(left Expr[bool], right Expr[bool]) R Or func(left Expr[bool], right Expr[bool]) R If func(condition Expr[bool], then Expr[T], otherwise Expr[T]) R }
ExprCases selects one handler per Expr variant for ExprFold.
type Instruction ¶
type Instruction interface {
// contains filtered or unexported methods
}
type InstructionCases ¶
type InstructionCases[R any] struct { Push func(Before Depth, Value Value) R LoadInteger func(Before Depth, Name string) R IntegerAdd func(Before Depth) R IntegerSubtract func(Before Depth) R IntegerMultiply func(Before Depth) R IntegerDivide func(Before Depth) R IntegerModulo func(Before Depth) R }
InstructionCases selects one handler per Instruction variant for InstructionFold.
type IntVariable ¶
type IntVariable struct {
Name string
}
type IntegerAdd ¶
type IntegerAdd struct {
Before Depth
}
type IntegerDivide ¶
type IntegerDivide struct {
Before Depth
}
type IntegerModulo ¶
type IntegerModulo struct {
Before Depth
}
type IntegerMultiply ¶
type IntegerMultiply struct {
Before Depth
}
type IntegerOperation ¶
type IntegerOperation interface {
// contains filtered or unexported methods
}
type IntegerOperationCases ¶
type IntegerOperationCases[R any] struct { AddOperation func() R SubtractOperation func() R MultiplyOperation func() R DivideOperation func() R ModuloOperation func() R }
IntegerOperationCases selects one handler per IntegerOperation variant for IntegerOperationFold.
type IntegerOperationEqOverrides ¶
type IntegerOperationEqOverrides struct {
AddOperation func(x, y AddOperation) (eq, handled bool)
SubtractOperation func(x, y SubtractOperation) (eq, handled bool)
MultiplyOperation func(x, y MultiplyOperation) (eq, handled bool)
DivideOperation func(x, y DivideOperation) (eq, handled bool)
ModuloOperation func(x, y ModuloOperation) (eq, handled bool)
}
IntegerOperationEqOverrides carries optional per-variant hooks for IntegerOperationEqualWith. A hook returning handled=false falls through to the derived comparison.
type IntegerSubtract ¶
type IntegerSubtract struct {
Before Depth
}
type LoadInteger ¶
type ModuloOperation ¶
type ModuloOperation struct{}
type MultiplyOperation ¶
type MultiplyOperation struct{}
type ReadsEnvironment ¶
type ReadsEnvironment struct{}
type RuntimeError ¶
type RuntimeError struct{ Message string }
func (RuntimeError) Error ¶
func (e RuntimeError) Error() string
type RuntimeFailed ¶
type RuntimeFailed[T any] struct { Error RuntimeError }
type SomeExpr ¶
type SomeExpr interface {
// contains filtered or unexported methods
}
SomeExpr is the existential parse boundary. Its finite variants expose the hidden result type through exhaustive matching without any in the checked evaluator.
type SomeExprCases ¶
type SomeExprCases[R any] struct { SomeInt func(Expression Expr[int]) R SomeBool func(Expression Expr[bool]) R SomeString func(Expression Expr[string]) R }
SomeExprCases selects one handler per SomeExpr variant for SomeExprFold.
type SomeExprEqOverrides ¶
type SomeExprEqOverrides struct {
SomeInt func(x, y SomeInt) (eq, handled bool)
SomeBool func(x, y SomeBool) (eq, handled bool)
SomeString func(x, y SomeString) (eq, handled bool)
}
SomeExprEqOverrides carries optional per-variant hooks for SomeExprEqualWith. A hook returning handled=false falls through to the derived comparison.
type SomeString ¶
type Stack ¶
type Stack interface {
// contains filtered or unexported methods
}
Stack[n] is sealed and can only be created through depth-preserving ops.
func EmptyStack ¶
func EmptyStack() Stack
func PushInteger ¶
PushInteger is an executable n -> n+1 bytecode transition. The result index is derived from the input stack, so callers cannot forge its stack effect.
func TransportStack ¶
TransportStack changes only the static presentation of a stack depth. The equality proof is discharged by refl and erased; the stack representation is unchanged. This is the equality-witness bridge needed after existential parsing or bytecode composition reveals two normalized depths are equal.
type StringValue ¶
type StringValue struct {
Value string
}
type StringVariable ¶
type StringVariable struct {
Name string
}
type SubtractOperation ¶
type SubtractOperation struct{}
type ValueCases ¶
type ValueCases[R any] struct { IntValue func(Value int) R BoolValue func(Value bool) R StringValue func(Value string) R }
ValueCases selects one handler per Value variant for ValueFold.
type ValueEqOverrides ¶
type ValueEqOverrides struct {
IntValue func(x, y IntValue) (eq, handled bool)
BoolValue func(x, y BoolValue) (eq, handled bool)
StringValue func(x, y StringValue) (eq, handled bool)
}
ValueEqOverrides carries optional per-variant hooks for ValueEqualWith. A hook returning handled=false falls through to the derived comparison.