Type sections

Example:

  1. type # example demonstrating mutually recursive types
  2. Node = ref object # an object managed by the garbage collector (ref)
  3. le, ri: Node # left and right subtrees
  4. sym: ref Sym # leaves contain a reference to a Sym
  5. Sym = object # a symbol
  6. name: string # the symbol's name
  7. line: int # the line the symbol was declared in
  8. code: Node # the symbol's abstract syntax tree

A type section begins with the type keyword. It contains multiple type definitions. A type definition binds a type to a name. Type definitions can be recursive or even mutually recursive. Mutually recursive types are only possible within a single type section. Nominal types like objects or enums can only be defined in a type section.