Optionals

Optional Type

To declare an optional type you need first enter type you want to make optional and after place a question mark ?. You can define optional type like this:

main {
  a: int?
}

In The Programming Language you can make any type (except void) optional:

main {
  a: any?
  b: bool?
  c: byte?
  d: char?
  e: float?
  f: int?
  g: str?
}

Default Value

Default value of optional type is nil, below declarations are identical:

main {
  a: int?
  b: int? = nil
}

Optional Function

To declare a function optional you need to place it within parenthesis, otherwise optional type will be applied to return type of function, not to function itself:

main {
  optionalFunction: (() -> int)?
}