Documentation ¶
Overview ¶
Package types provides data structures for types in GoCaml.
Index ¶
- Constants
- Variables
- func Debug(t Type) string
- func Equals(l, r Type) bool
- func Visit(vis Visitor, t Type)
- type Array
- type Bool
- type Env
- type External
- type Float
- type Fun
- type Instantiation
- type Int
- type Option
- type String
- type Tuple
- type Type
- type Unit
- type Var
- type VarID
- type VarMapping
- type Visitor
Constants ¶
View Source
const GenericLevel = 2147483647
INT32_MAX. When this value is specified to variable's level, it means that the variable is 'forall a.a' (generic bound type variable). It's because any other level is smaller than the GenericLevel. Type inference algorithm treats type variables whose level is larger than current level as generic type.
Variables ¶
View Source
var ( UnitType = &Unit{} BoolType = &Bool{} IntType = &Int{} FloatType = &Float{} StringType = &String{} )
Make singleton type values because it doesn't have any contextual information
Functions ¶
Types ¶
type Env ¶
type Env struct { // Types for declarations. This is referred by type variables to resolve // type variables' actual types // // XXX: // Currently nested identifiers don't work. Example: // let // x = 42 // in // let x = true in print_bool (x); // print_int (x) // We need alpha transform before type inference in order to ensure // all symbol names are unique. DeclTable map[string]Type // External variable names which are referred but not defined. // External variables are exposed as external symbols in other object files. Externals map[string]*External // GoCaml uses let-polymorphic type inference. It means that instantiation occurs when new // symbol is introduced. So instantiation only occurs at variable reference. RefInsts map[string]*Instantiation // Mappings from generic type to instantiated types for each declarations. // e.g. // 'a -> 'a => {int -> int, bool -> bool, float -> float} // // Note: This is set in sema/deref.go PolyTypes map[Type][]*Instantiation }
Result of type analysis.
func (*Env) DumpExternals ¶
func (env *Env) DumpExternals()
func (*Env) DumpPolyTypes ¶
func (env *Env) DumpPolyTypes()
func (*Env) DumpVariables ¶
func (env *Env) DumpVariables()
type Instantiation ¶
type Instantiation struct { // From is a generic type variable instantiated. From Type // To is a type variable instantiated from generic type variable. To Type // Mapping from ID of generic type variable to actual instantiated type variable Mapping []*VarMapping }
Instantiation is the information of instantiation of a generic type.
type Var ¶
func NewGeneric ¶
func NewGeneric() *Var
func (*Var) SetGeneric ¶
func (t *Var) SetGeneric()
type VarMapping ¶
type Visitor ¶
type Visitor interface { // VisitTopdown defines the process when a type is visited. This method is called before // children are visited. // Returned value is a next visitor to use for succeeding visit. When wanting to stop // visiting, please return nil. // A visitor visits in depth-first order. VisitTopdown(t Type) Visitor // VisitBottomup defines the process when a type is visited. This method is called after // children were visited. When VisitTopdown returned nil, this method won't be caled for the type. VisitBottomup(t Type) }
Visitor is an interface for the structs which is used for traversing Type.
Click to show internal directories.
Click to hide internal directories.