Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( Undef = &Operator{"Undef", []Type{}} Error = &Operator{"Error", []Type{}} None = &Operator{"None", []Type{}} Bool = &Operator{"Bool", []Type{}} Int = &Operator{"Int", []Type{}} Float = &Operator{"Float", []Type{}} String = &Operator{"String", []Type{}} Pattern = &Operator{"Pattern", []Type{}} // TODO(jaq): use composite type so we can typecheck the bucket directly, e.g. hist[j] = i Buckets = &Operator{"Buckets", []Type{}} )
Builtin types
var Builtins = map[string]Type{ "int": Function(NewVariable(), Int), "bool": Function(NewVariable(), Bool), "float": Function(NewVariable(), Float), "string": Function(NewVariable(), String), "timestamp": Function(Int), "len": Function(String, Int), "settime": Function(Int, None), "strptime": Function(String, String, None), "strtol": Function(String, Int, Int), "tolower": Function(String, String), "getfilename": Function(String), }
Builtins is a mapping of the builtin language functions to their type definitions.
Functions ¶
func IsComplete ¶
IsComplete returns true if the type and all its arguments have non-variable exemplars.
func IsDimension ¶
IsDimension returns true if the given type is a Dimension type.
func IsErrorType ¶
isErrorType indicates that a given type is the result of a type error.
func IsFunction ¶
IsFunction returns true if the given type is a Function type.
func Unify ¶
Unify performs type unification of both parameter Types. It returns the least upper bound of both types, the smallest type that is capable of representing both parameters. If either type is a type variable, then that variable is unified with the LUB. In reporting errors, it is assumed that a is the expected type and b is the type observed.
Types ¶
type Operator ¶
type Operator struct { // Name is a common name for this operator Name string // Args is the sequence of types that are parameters to this type. They // may be fully bound type operators, or partially defined (i.e. contain // TypeVariables) in which case they represent polymorphism in the operator // they are argyments to. Args []Type }
Operator represents a type scheme in the type system.
func Dimension ¶
Dimension is a convenience method which instantiates a new Dimension type scheme, with the given args as the dimensions of the type.
func Function ¶
Function is a convenience method, which instantiates a new Function type scheme, with the given args as parameters.
type Type ¶
type Type interface { // Root returns an exemplar Type after unification occurs. If the type // system is complete after unification, Root will be a TypeOperator. Root() Type // String returns a string representation of a Type. String() string }
Type represents a type in the mtail program.
func FreshType ¶
FreshType returns a new type from the provided type scheme, replacing any unbound type variables with new type variables.
func InferCaprefType ¶
inferCaprefType determines a type for a capturing group, based on contents of that capture group.
func LeastUpperBound ¶
LeastUpperBound returns the smallest type that may contain both parameter types.
type TypeError ¶
type TypeError struct {
// contains filtered or unexported fields
}
TypeError describes an error in which a type was expected, but another was encountered.
type Variable ¶
Variable represents an unbound type variable in the type system.
func (*Variable) Root ¶
Root returns an exemplar of this TypeVariable, in this case the root of the unification tree.
func (*Variable) SetInstance ¶
SetInstance sets the exemplar instance of this TypeVariable, during unification.