types

package
v0.0.0-...-93548a8 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

View Source
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 Equals

func Equals(t1, t2 Type) bool

Equals compares two types, testing for equality

func IsComplete

func IsComplete(t Type) bool

IsComplete returns true if the type and all its arguments have non-variable exemplars.

func IsDimension

func IsDimension(t Type) bool

IsDimension returns true if the given type is a Dimension type.

func IsErrorType

func IsErrorType(t Type) bool

isErrorType indicates that a given type is the result of a type error.

func IsFunction

func IsFunction(t Type) bool

IsFunction returns true if the given type is a Function type.

func Unify

func Unify(a, b Type) error

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

func Dimension(args ...Type) *Operator

Dimension is a convenience method which instantiates a new Dimension type scheme, with the given args as the dimensions of the type.

func Function

func Function(args ...Type) *Operator

Function is a convenience method, which instantiates a new Function type scheme, with the given args as parameters.

func (*Operator) Root

func (t *Operator) Root() Type

Root returns an exemplar of a TypeOperator, i.e. itself.

func (*Operator) String

func (t *Operator) String() (s string)

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

func FreshType(t Type) Type

FreshType returns a new type from the provided type scheme, replacing any unbound type variables with new type variables.

func InferCaprefType

func InferCaprefType(re *syntax.Regexp, cap int) Type

inferCaprefType determines a type for a capturing group, based on contents of that capture group.

func LeastUpperBound

func LeastUpperBound(a, b Type) Type

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.

func (*TypeError) Error

func (e *TypeError) Error() string

type Variable

type Variable struct {
	ID int

	Instance *Type
	// contains filtered or unexported fields
}

Variable represents an unbound type variable in the type system.

func NewVariable

func NewVariable() *Variable

NewVariable constructs a new unique TypeVariable.

func (*Variable) Root

func (t *Variable) Root() Type

Root returns an exemplar of this TypeVariable, in this case the root of the unification tree.

func (*Variable) SetInstance

func (t *Variable) SetInstance(t1 *Type)

SetInstance sets the exemplar instance of this TypeVariable, during unification.

func (*Variable) String

func (t *Variable) String() string

Jump to

Keyboard shortcuts

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