Skip to main content
  1. The pint° programming language/
  2. Language overview/

Type definitions

pint° still have no types with complex behavior, but you can introduce product types and sum types with the type keyword. The types defined by the type keyword are opaque and have structural identity.

All types are made of a type name with optional type parameters and one or more type variants.

Product types #

Product types are described by providing parameters delimited by commas.

1
2
3
4
5
type User = User(
  int id,
  String name,
  int age,
)

Sum types #

You can declare multiple variants of a type by separating each variant with the pseudo-operator +.

type LogLevel = Debug + Info + Warn + Error + Fatal

Combining both types #

You can combine both product types and sum types to make more complex types.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import @async

type Complex(T) = Complex(
  [] listOfAny,
  [T] listOfT,
  {T} set,
  {T: T} map,
  T? maybeT,
  Future(T) futureOfT,
  int aSimpleInt,
  {{T?} : [Future(T)]} aMonster
)