Documentation
¶
Overview ¶
Package types contains data structures and algorithms for dealing with value types in Reflow. In particular, it defines type-trees, constructors for type trees, together with unification and subtyping algorithms.
A Reflow type is one of:
bottom the type of no values int the type of arbitrary precision integers string the type of (utf-8 encoded) strings bool the type of booleans file the type of files dir the type of directories unit the type of single-valued unit/void fileset the type of filesets (legacy) <ident> a type reference to ident [t] the type of lists of element type t [t1:t2] the type of maps of index type t1, element type t2 (t1, t2, ..., tn) the type of tuples of type t1, ..., tn func(arg1 t1, arg2 t2, ..., argn tn) t the type of function with arguments t1, ..., tn, and return type t {k1: t1, k2: t2, ..., kn: tn} the type of struct with fields k1, ..., kn, of types t1, ..., tn module{I1: t1, I2: t2, ..., In: tn, type a1 at1, type a2 at2} the type of module with values I1, ... In, of types t1, ..., tn and type aliases a1, a2 of at1, at2.
See package grail.com/reflow/syntax for parsing concrete syntax into type trees.
Two types are unified by recursively computing the common subtype of the two arguments. Subtyping is limited to structs and modules; type equality is required for all other types.
Index ¶
- Variables
- func FieldsString(fields []*Field) string
- type Env
- type Field
- type Kind
- type Symtab
- type T
- func Error(err error) *T
- func Errorf(format string, args ...interface{}) *T
- func Func(elem *T, fields ...*Field) *T
- func Labeled(label string, t *T) *T
- func List(elem *T) *T
- func Map(index, elem *T) *T
- func Module(fields []*Field, aliases []*Field) *T
- func Promote(t *T) *T
- func Ref(path ...string) *T
- func Struct(fields ...*Field) *T
- func Tuple(fields ...*Field) *T
- func (t *T) Alias(id string) *T
- func (t *T) Assign(u *T) *T
- func (t *T) Copy() *T
- func (t *T) Equal(u *T) bool
- func (t *T) Field(n string) *T
- func (t *T) FieldMap() map[string]*T
- func (t *T) Ident() string
- func (t *T) String() string
- func (t *T) StructurallyEqual(u *T) bool
- func (t *T) Sub(u *T) bool
- func (t *T) Tupled() *T
- func (t *T) Unify(u *T) *T
Constants ¶
This section is empty.
Variables ¶
var ( Bottom = &T{Kind: BottomKind} Int = &T{Kind: IntKind} Float = &T{Kind: FloatKind} String = &T{Kind: StringKind} Bool = &T{Kind: BoolKind} File = &T{Kind: FileKind} Dir = &T{Kind: DirKind} Unit = &T{Kind: UnitKind} Fileset = &T{Kind: FilesetKind} )
Convenience vars for common types.
Functions ¶
func FieldsString ¶
FieldsString returns a parseable string representation of the given fields.
Types ¶
type Env ¶
type Env struct {
Values, Types Symtab
// contains filtered or unexported fields
}
Env represents a type environment that binds value and type identifiers to *Ts.
type Kind ¶
type Kind int
Kind represents a type's kind.
const ( // ErrorKind is an illegal type. ErrorKind Kind = iota // BottomKind is a value-less type. BottomKind // IntKind is the type of arbitrary precision integers. IntKind // StringKind is the type of UTF-8 encoded strings. StringKind // BoolKind is the type of booleans. BoolKind // FileKind is the type of files. FileKind // DirKind is the type of directories. DirKind // UnitKind is a 1-valued type. UnitKind // ListKind is the type of lists. ListKind // MapKind is the type of maps. MapKind // TupleKind is the kind of n-tuples of values (containing positional fields). TupleKind // FuncKind is the type of funcs (arguments and return types). FuncKind // StructKind is the type of structs (containing named fields). StructKind // ModuleKind is the type of modules. They are like structs, // but: (1) will eventually also contain types; (2) can never // be subject to delayed evaluation: their values are known // at compile time. ModuleKind // RefKind is a pseudo-kind to carry type alias references. RefKind // FloatKind is the type of arbitrary precision floats. FloatKind // FilesetKind is the type of filesets. FilesetKind )
type T ¶
type T struct { // Kind is the kind of the type. See above. Kind Kind // Index is the type of the type's index; used in maps. Index *T // Elem is the type of the type's elem; used in lists, maps, and funcs. Elem *T // Fields stores struct and tuple fields, as well as func arguments. Fields []*Field // Aliases stores a module's (exported) type aliases. Aliases []*Field // Error holds the type's error. Error error // Path is a type reference path, used by RefKind. // It is also used after alias expansion to retain identifiers // for pretty printing. Path []string // Label is an optional label for this type. // It does not affect the type's semantics. Label string // Flow is a flag indicating that types of this value are derived // from *reflow.Flow evaluations. This is used in the type checker // to check for "immediate" evaluation. Flow bool }
A T is a Reflow type. The zero of a T is a TypeError.
func (*T) Assign ¶
Assign assigns type t from type u: if either t or u are error types, it returns a new error; if u is a Flow type, this flag is set on the returned type. Otherwise, t is returned unadulterated.
func (*T) StructurallyEqual ¶
StructurallyEqual tells whether type t is structurall equal to type u. Structural equality permits type aliases and considers two aliases equal if their paths are equal.