typed

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 1 Imported by: 0

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

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

func EffectEqual(a, b Effect) bool

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 ExprFold

func ExprFold[T any, R any](e Expr[T], cs ExprCases[T, R]) R

ExprFold reduces Expr[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 PopStack

func PopStack(stack Stack) (Value, Stack)

func SomeExprEqual

func SomeExprEqual(a, b SomeExpr) bool

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

func ValueEqual(a, b Value) bool

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 Add

type Add struct {
	Left  Expr[int]
	Right Expr[int]
}

type AddOperation

type AddOperation struct{}

type And

type And struct {
	Left  Expr[bool]
	Right Expr[bool]
}

type Bool

type Bool struct {
	Value bool
}

type BoolValue

type BoolValue struct {
	Value bool
}

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

type DepthCases[R any] struct {
	ZeroDepth func() R
	NextDepth func(Previous Depth) R
}

DepthCases selects one handler per Depth variant for DepthFold.

type Divide

type Divide struct {
	Left  Expr[int]
	Right Expr[int]
}

type DivideOperation

type DivideOperation struct{}

type Effect

type Effect interface {
	// contains filtered or unexported methods
}

func EffectOf

func EffectOf[T any](expression Expr[T]) Effect

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 Environment struct {
	Ints    map[string]int
	Bools   map[string]bool
	Strings map[string]string
}

type EqualBool

type EqualBool struct {
	Left  Expr[bool]
	Right Expr[bool]
}

type EqualInt

type EqualInt struct {
	Left  Expr[int]
	Right Expr[int]
}

type EqualString

type EqualString struct {
	Left  Expr[string]
	Right Expr[string]
}

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 Evaluated

type Evaluated[T any] struct {
	Value T
}

type Expr

type Expr[T any] interface {
	// contains filtered or unexported methods
}

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 Greater

type Greater struct {
	Left  Expr[int]
	Right Expr[int]
}

type GreaterEqual

type GreaterEqual struct {
	Left  Expr[int]
	Right Expr[int]
}

type If

type If[T any] struct {
	Condition Expr[bool]
	Then      Expr[T]
	Otherwise Expr[T]
}

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 Int

type Int struct {
	Value int
}

type IntValue

type IntValue struct {
	Value int
}

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 Less

type Less struct {
	Left  Expr[int]
	Right Expr[int]
}

type LessEqual

type LessEqual struct {
	Left  Expr[int]
	Right Expr[int]
}

type LoadInteger

type LoadInteger struct {
	Before Depth
	Name   string
}

type Modulo

type Modulo struct {
	Left  Expr[int]
	Right Expr[int]
}

type ModuloOperation

type ModuloOperation struct{}

type Multiply

type Multiply struct {
	Left  Expr[int]
	Right Expr[int]
}

type MultiplyOperation

type MultiplyOperation struct{}

type Negate

type Negate struct {
	Value Expr[int]
}

type NextDepth

type NextDepth struct {
	Previous Depth
}

type Not

type Not struct {
	Value Expr[bool]
}

type Or

type Or struct {
	Left  Expr[bool]
	Right Expr[bool]
}

type Pure

type Pure struct{}

type Push

type Push struct {
	Before Depth
	Value  Value
}

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 SomeBool

type SomeBool struct {
	Expression Expr[bool]
}

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 SomeInt

type SomeInt struct {
	Expression Expr[int]
}

type SomeString

type SomeString struct {
	Expression Expr[string]
}

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

func PushInteger(stack Stack, value int) Stack

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 PushStack

func PushStack(stack Stack, value Value) Stack

func TransportStack

func TransportStack(stack Stack) Stack

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 String

type String struct {
	Value string
}

type StringValue

type StringValue struct {
	Value string
}

type StringVariable

type StringVariable struct {
	Name string
}

type Subtract

type Subtract struct {
	Left  Expr[int]
	Right Expr[int]
}

type SubtractOperation

type SubtractOperation struct{}

type Value

type Value interface {
	// contains filtered or unexported methods
}

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.

type ZeroDepth

type ZeroDepth struct{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL