A language for programming recursive circuits

2. Language
2.2. Type system
2.2.1. Type integration
2.2.1. Type integration

When functions invoke gates (implementations of transformations in Go), the argument Ko values are “integrated” into, i.e. converted to, the Go type structure of the gate. The process of type integration (from Ko to Go) is designed to aid the programmer both in flexibility (and genericity), as well as in safety.

Type integration enforces the following rules in converting a Ko type to a Go type.

Suppose T is a type (excluding varieties which are not convertible to Go types). Then the following safe conversions will be applied automatically, as necessary:

// Ko types on left, Go types on right
T -> T   // e.g. String -> string
T -> *T   // e.g. String -> *string
T -> []T   // e.g. String -> []string
*T -> []T   // e.g. *String -> []string

Type integration is performed recursively to structure fields as well.

When converting Ko structures to Go structures, the compiler enforces two additional rules that add flexibility and safety.

First (safety), for every non-pointer or non-slice field in the (receiving) Go structure, the compiler ensures that field is explicitly set in the Ko program. (This rule has its roots in the required field semantic in Protocol Buffers .)

Second (flexibility), the Ko structure being integrated into a Go structure can be wider: it can have more fields than are recognized by the Go structure type. Such additional fields are discarded.

All integration rules are applied recursively throughout the full depth of types at play.