Documentation
¶
Index ¶
- func ReturnSubs(s Subs)
- type Apply
- type Cloner
- type Coercible
- type Env
- type Expression
- type Fresher
- type FunctionType
- func (ft *FunctionType) Apply(subs Subs) Substitutable
- func (ft *FunctionType) Arg() Type
- func (ft *FunctionType) Block() *FunctionType
- func (ft *FunctionType) Eq(other Type) bool
- func (ft *FunctionType) Format(s fmt.State, c rune)
- func (ft *FunctionType) FreeTypeVar() TypeVarSet
- func (ft *FunctionType) Name() string
- func (ft *FunctionType) Normalize(k, v TypeVarSet) (Type, error)
- func (ft *FunctionType) Ret(recursive bool) Type
- func (ft *FunctionType) ReturnType() Type
- func (ft *FunctionType) SetBlock(block *FunctionType)
- func (ft *FunctionType) String() string
- func (ft *FunctionType) Supertypes() []Type
- func (ft *FunctionType) Types() Types
- type Inferer
- type Lambda
- type Let
- type LetRec
- type Literal
- type Namer
- type NonNullType
- func (t NonNullType) Apply(subs Subs) Substitutable
- func (t NonNullType) Eq(other Type) bool
- func (t NonNullType) Format(s fmt.State, c rune)
- func (t NonNullType) FreeTypeVar() TypeVarSet
- func (t NonNullType) Name() string
- func (t NonNullType) Normalize(k, v TypeVarSet) (Type, error)
- func (t NonNullType) String() string
- func (t NonNullType) Supertypes() []Type
- func (t NonNullType) Types() Types
- type NullableTypeVariable
- type Scheme
- type SimpleEnv
- func (env *SimpleEnv) Add(name string, scheme *Scheme) Env
- func (env *SimpleEnv) Apply(subs Subs) Substitutable
- func (env *SimpleEnv) Clone() Env
- func (env *SimpleEnv) FreeTypeVar() TypeVarSet
- func (env *SimpleEnv) GetDynamicScopeType() Type
- func (env *SimpleEnv) Remove(name string) Env
- func (env *SimpleEnv) SchemeOf(name string) (*Scheme, bool)
- func (env *SimpleEnv) SetDynamicScopeType(t Type)
- type SimpleFresher
- type Subs
- type Substitutable
- type Substitution
- type Type
- type TypeVarSet
- type TypeVariable
- func (tv TypeVariable) Apply(subs Subs) Substitutable
- func (tv TypeVariable) Eq(other Type) bool
- func (tv TypeVariable) Format(s fmt.State, c rune)
- func (tv TypeVariable) FreeTypeVar() TypeVarSet
- func (tv TypeVariable) Name() string
- func (tv TypeVariable) Normalize(k, v TypeVarSet) (Type, error)
- func (tv TypeVariable) String() string
- func (tv TypeVariable) Supertypes() []Type
- func (tv TypeVariable) Types() Types
- type Typer
- type Types
- type UnificationError
- type Var
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReturnSubs ¶
func ReturnSubs(s Subs)
ReturnSubs is a no-op function for compatibility with object pooling
Types ¶
type Apply ¶
type Apply interface {
Expression
Fn() Expression
}
Apply is an Expression/AST node that represents a function application
type Coercible ¶
Coercible is implemented by types that accept coercion from other types. This is used primarily for custom scalar types that can accept values of built-in types (e.g., a URL scalar accepting a String literal).
type Env ¶
type Env interface {
SchemeOf(name string) (*Scheme, bool)
Clone() Env
Add(name string, scheme *Scheme) Env
Remove(name string) Env
FreeTypeVar() TypeVarSet
Apply(subs Subs) Substitutable
GetDynamicScopeType() Type
SetDynamicScopeType(t Type)
}
Env represents a type environment
type Expression ¶
type Expression interface {
Body() Expression
}
Expression is basically an AST node
type Fresher ¶
type Fresher interface {
Fresh() TypeVariable
}
Fresher interface for generating fresh type variables
type FunctionType ¶
type FunctionType struct {
// contains filtered or unexported fields
}
FunctionType represents a function type
func NewFnType ¶
func NewFnType(arg, ret Type) *FunctionType
func (*FunctionType) Apply ¶
func (ft *FunctionType) Apply(subs Subs) Substitutable
func (*FunctionType) Block ¶
func (ft *FunctionType) Block() *FunctionType
Block returns the optional block argument type
func (*FunctionType) Eq ¶
func (ft *FunctionType) Eq(other Type) bool
func (*FunctionType) FreeTypeVar ¶
func (ft *FunctionType) FreeTypeVar() TypeVarSet
func (*FunctionType) Name ¶
func (ft *FunctionType) Name() string
func (*FunctionType) Normalize ¶
func (ft *FunctionType) Normalize(k, v TypeVarSet) (Type, error)
func (*FunctionType) Ret ¶
func (ft *FunctionType) Ret(recursive bool) Type
Ret returns the return type, with optional recursive parameter for compatibility
func (*FunctionType) ReturnType ¶
func (ft *FunctionType) ReturnType() Type
Convenience method for getting return type
func (*FunctionType) SetBlock ¶
func (ft *FunctionType) SetBlock(block *FunctionType)
SetBlock sets the block argument type
func (*FunctionType) String ¶
func (ft *FunctionType) String() string
func (*FunctionType) Supertypes ¶
func (ft *FunctionType) Supertypes() []Type
func (*FunctionType) Types ¶
func (ft *FunctionType) Types() Types
type Lambda ¶
type Lambda interface {
Expression
Namer // name of the parameter
}
Lambda is an Expression/AST node that represents a lambda abstraction
type Let ¶
type Let interface {
Expression
Namer // name of the bound variable
Def() Expression // definition
}
Let is an Expression/AST node that represents let polymorphism
type NonNullType ¶
type NonNullType struct {
Type Type
}
NonNullType represents a non-nullable type wrapper
func (NonNullType) Apply ¶
func (t NonNullType) Apply(subs Subs) Substitutable
func (NonNullType) Eq ¶
func (t NonNullType) Eq(other Type) bool
func (NonNullType) FreeTypeVar ¶
func (t NonNullType) FreeTypeVar() TypeVarSet
func (NonNullType) Name ¶
func (t NonNullType) Name() string
func (NonNullType) Normalize ¶
func (t NonNullType) Normalize(k, v TypeVarSet) (Type, error)
func (NonNullType) String ¶
func (t NonNullType) String() string
func (NonNullType) Supertypes ¶
func (t NonNullType) Supertypes() []Type
func (NonNullType) Types ¶
func (t NonNullType) Types() Types
type NullableTypeVariable ¶
type NullableTypeVariable struct {
TypeVariable
}
NullableTypeVariable is a type variable that carries a nullability taint. It is produced by null literals. When unified with a NonNullType during binding, it strips the NonNull wrapper, ensuring that null always resolves to a nullable type.
func (NullableTypeVariable) Apply ¶
func (ntv NullableTypeVariable) Apply(subs Subs) Substitutable
func (NullableTypeVariable) Eq ¶
func (ntv NullableTypeVariable) Eq(other Type) bool
func (NullableTypeVariable) String ¶
func (ntv NullableTypeVariable) String() string
type Scheme ¶
type Scheme struct {
// contains filtered or unexported fields
}
Scheme represents a type scheme for polymorphic types
func Generalize ¶
Generalize creates a type scheme by quantifying over type variables that are free in the type but not free in the environment
func NewScheme ¶
func NewScheme(tvs []TypeVariable, t Type) *Scheme
NewScheme creates a new type scheme
func (*Scheme) Apply ¶
func (s *Scheme) Apply(subs Subs) Substitutable
Apply applies a substitution to a scheme
func (*Scheme) FreeTypeVar ¶
func (s *Scheme) FreeTypeVar() TypeVarSet
FreeTypeVar returns the free type variables in the scheme
func (*Scheme) TypeVars ¶
func (s *Scheme) TypeVars() []TypeVariable
TypeVars returns the bound type variables
type SimpleEnv ¶
type SimpleEnv struct {
// contains filtered or unexported fields
}
SimpleEnv is a simple implementation of Env
func (*SimpleEnv) Apply ¶
func (env *SimpleEnv) Apply(subs Subs) Substitutable
Apply applies a substitution to the environment
func (*SimpleEnv) FreeTypeVar ¶
func (env *SimpleEnv) FreeTypeVar() TypeVarSet
FreeTypeVar returns the free type variables in the environment
func (*SimpleEnv) GetDynamicScopeType ¶
GetDynamicScopeType returns the current dynamic scope type
func (*SimpleEnv) SetDynamicScopeType ¶
SetDynamicScopeType sets the current dynamic scope type
type SimpleFresher ¶
type SimpleFresher struct {
// contains filtered or unexported fields
}
SimpleFresher is a simple implementation of Fresher
func NewSimpleFresher ¶
func NewSimpleFresher() *SimpleFresher
NewSimpleFresher creates a new SimpleFresher
func (*SimpleFresher) Fresh ¶
func (f *SimpleFresher) Fresh() TypeVariable
Fresh generates a fresh type variable
type Subs ¶
type Subs map[TypeVariable]Type
Subs represents a substitution mapping from type variables to types
func Assignable ¶
Assignable attempts to unify two types, returning a substitution or error. If unification fails, it checks subtyping: have can be assigned to want if have is a subtype of want.
func (Subs) Add ¶
func (s Subs) Add(tv TypeVariable, t Type) Subs
Add adds a substitution mapping and returns the updated substitution
type Substitutable ¶
type Substitutable interface {
Apply(Subs) Substitutable
FreeTypeVar() TypeVarSet
}
Substitutable is any type that can have substitutions applied and knows its free type variables
type Substitution ¶
type Substitution struct {
Tv TypeVariable
T Type
}
Substitution represents a single type variable to type mapping
type Type ¶
type Type interface {
Substitutable
Name() string
Normalize(TypeVarSet, TypeVarSet) (Type, error)
Types() Types
Eq(Type) bool
// Supertypes returns the direct supertypes of this type.
// For example, NonNullType{String} returns [String].
// Module types implementing interfaces return those interfaces.
// Most types return nil (no supertypes).
Supertypes() []Type
// fmt.Formatter
fmt.Stringer
}
Type represents all possible type constructors with nullability support
func Instantiate ¶
Instantiate creates a fresh instance of a type scheme
type TypeVarSet ¶
type TypeVarSet map[TypeVariable]bool
TypeVarSet represents a set of type variables
func NewTypeVarSet ¶
func NewTypeVarSet(tvs ...TypeVariable) TypeVarSet
NewTypeVarSet creates a new TypeVarSet
func (TypeVarSet) Add ¶
func (tvs TypeVarSet) Add(tv TypeVariable)
Add adds a type variable to the set
func (TypeVarSet) Contains ¶
func (tvs TypeVarSet) Contains(tv TypeVariable) bool
Contains checks if a type variable is in the set
func (TypeVarSet) Remove ¶
func (tvs TypeVarSet) Remove(tv TypeVariable)
Remove removes a type variable from the set
func (TypeVarSet) ToSlice ¶
func (tvs TypeVarSet) ToSlice() []TypeVariable
ToSlice converts the set to a slice
func (TypeVarSet) Union ¶
func (tvs TypeVarSet) Union(other TypeVarSet) TypeVarSet
Union returns the union of two TypeVarSets
type TypeVariable ¶
type TypeVariable rune
TypeVariable represents a type variable
func (TypeVariable) Apply ¶
func (tv TypeVariable) Apply(subs Subs) Substitutable
func (TypeVariable) Eq ¶
func (tv TypeVariable) Eq(other Type) bool
func (TypeVariable) FreeTypeVar ¶
func (tv TypeVariable) FreeTypeVar() TypeVarSet
func (TypeVariable) Name ¶
func (tv TypeVariable) Name() string
func (TypeVariable) Normalize ¶
func (tv TypeVariable) Normalize(k, v TypeVarSet) (Type, error)
func (TypeVariable) String ¶
func (tv TypeVariable) String() string
func (TypeVariable) Supertypes ¶
func (tv TypeVariable) Supertypes() []Type
func (TypeVariable) Types ¶
func (tv TypeVariable) Types() Types
type Typer ¶
type Typer interface {
Type() Type
}
Typer is an Expression node that knows its own Type
type Types ¶
type Types []Type
Types represents a slice of types
func BorrowTypes ¶
BorrowTypes creates a new slice of types with the given capacity This is for compatibility with object pooling patterns
type UnificationError ¶
type UnificationError struct {
Have, Want Type
}
UnificationError represents errors during unification
func (UnificationError) Error ¶
func (e UnificationError) Error() string
type Var ¶
type Var interface {
Expression
Namer
Typer
}
Var is an expression representing a variable