types

package
v0.0.0-...-4dae95d Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package types is Writ's type algebra and checker.

Check walks already-expanded forms. It does not evaluate or read files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(t Type) ([]byte, error)

Encode serializes t for package export tables.

func MustEncode

func MustEncode(t Type) []byte

MustEncode is Encode panicking on error.

func PrintType

func PrintType(t Type) string

PrintType renders t in the checker notation.

Types

type Alias

type Alias struct {
	Name    string
	Type    Type
	Members []string
}

Alias is a named type for display and host domain types.

type CheckResult

type CheckResult struct {
	Diagnostics []Diagnostic
	Hints       []TypeHint
	Export      Type
}

CheckResult is the output of Check.

func Check

func Check(forms []syntax.Form, prog runtime.Program, cfg Config) CheckResult

Check type-checks already-expanded forms and a compiled program.

type Config

type Config struct {
	Events  map[string][]PayloadKey
	Aliases []Alias
	Extra   map[string][]FnClause
	File    string
	Import  func(spec, fromFile string) (Type, []Diagnostic, error)
}

Config is host type information for Check.

type Diagnostic

type Diagnostic struct {
	Start   int
	End     int
	Message string
}

Diagnostic is a parse or type error.

type FnClause

type FnClause struct {
	Key    bool
	Args   []Type
	Keys   []FnKey
	Rest   bool
	Result Type
}

FnClause is one function clause: (fn (Args) Return) or keyed args. Rest is host/checker-only (runtime rest params / print builtin); it is not part of the Writ type language, PrintType, or Encode.

func KeyFn

func KeyFn(ret Type, keys ...FnKey) FnClause

KeyFn builds a keyed clause (fn (name: T ...) ret).

func PosFn

func PosFn(ret Type, args ...Type) FnClause

PosFn builds a positional clause (fn (args...) ret).

type FnKey

type FnKey struct {
	Name string
	Type Type
}

FnKey is a keyword argument or map field type.

type PayloadKey

type PayloadKey struct {
	Name string
	Type Type
}

PayloadKey is one event payload field.

type Type

type Type struct {
	// contains filtered or unexported fields
}

Type is a static type. Use the constructors such as IntType and Union.

func Any

func Any() Type

func BoolType

func BoolType() Type

func Decode

func Decode(b []byte) (Type, error)

Decode reads a type produced by Encode.

func Dynamic

func Dynamic(t Type) Type

func EmptyList

func EmptyList() Type

func EmptyMapType

func EmptyMapType() Type

func ExactSymbol

func ExactSymbol(s string) Type

func FalseType

func FalseType() Type

func FloatType

func FloatType() Type

func FnType

func FnType(clauses ...FnClause) Type

func IntType

func IntType() Type

func ListOf

func ListOf(el Type) Type

func MacroType

func MacroType() Type

func MapType

func MapType(keys []FnKey, rest *Type) Type

func Native

func Native[T any]() Type

Native maps a Go host type to (opaque from host named …) for in-process RegisterBuiltin / RegisterPackage. Encode uses package/name, not reflect IDs.

func NilType

func NilType() Type

func None

func None() Type

func Opaque

func Opaque(pkg string, name ...string) Type

Opaque is a nominal opaque. With only pkg: (opaque from P). With pkg and name: (opaque from P named T). Empty pkg and name is OpaqueType.

func OpaqueType

func OpaqueType() Type

OpaqueType is the universe of host/guest opaques.

func StringType

func StringType() Type

func SymbolType

func SymbolType() Type

func TrueType

func TrueType() Type

func Tuple

func Tuple(items ...Type) Type

func Union

func Union(ts ...Type) Type

func UnknownSymbol

func UnknownSymbol() Type

type TypeHint

type TypeHint struct {
	Start int
	End   int
	Text  string
}

TypeHint is an editor hover for a span.

Jump to

Keyboard shortcuts

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