Box type

+

OverviewTypes

Nil typeBoolean typeNumeric typesString typeArray typeMap typeStruct typeFunction typeFile typeBucket typeReference typesBox type

ExpressionsOperatorsGet expressionsIndex expressionsSlice expressionsGroupingLiteralsInstantiationsIdentifiersCall expressionsXml expressionsFunction literalsAs expressions

StatementsImport statementType declarationsVar declarationsFunction declarationsMethod declarationsAssign statementIf statementFor statementAssert statementReturn statementFail statementPanic statementYield statementBreak statementContinue statementDefer statementIncDec statementExpression statementBlock statement

A box holds a value and its type, which is typically not known at compile time. The box also holds a constraint, which enforces some rules on what types of values can be placed in the box. There are three ways of composing that constraint: unions, interfaces, kinds.

Union (A|B)

A union constraint (also known a sum type) combines multiple constraints, so that a value can be placed in the box if it satisfies any of those constraints.

Interface (interface{...})

An interface constraint has a list of methods that a value's type must implement to
be able to be placed in the box.

Kind (file)

A kind constraint describes the kind of a value. For example, it could be file value, file reference or string.

One could also think of it as partially revealing a type, which is used to gain access to kind methods.