Numeric types

Disco has four types which represent numbers:

  • Natural numbers, written N, , Nat, or Natural. These represent the counting numbers 0, 1, 2, … which can be added and multiplied.

    Disco> :type 5
    5 : 
    
  • Integers, written Z, , Int, or Integer, allow negative numbers such as -5. They extend the natural numbers with subtraction.

    Disco> :type -5
    -5 : 
    
  • Fractional numbers, written F, 𝔽, Frac, or Fractional, allow fractions like 2/3. They extend the natural numbers with division.

    Disco> :type 2/3
    2 / 3 : 𝔽
    
  • Rational numbers, written Q, , or Rational, allow both negative and fractional numbers, such as -2/3.

    Disco> :type -2/3
    -2 / 3 : 
    

We can arrange the four numeric types in a diamond shape, like this:

  Q
 / \
Z   F
 \ /
  N

Each type is a subset, or subtype, of the type or types above it. For example, the fact that N is below Z means that every natural number is also an integer.

  • The values of every numeric type can be added and multiplied.
  • The types on the upper left of the diamond (Z and Q) can also be subtracted.
  • The types on the upper right of the diamond (F and Q) can also be divided.
  • To move down and to the right (i.e. from Z to N, or from Q to F), you can use absolute value.
  • To move down and to the left (i.e. from F to N, or from Q to Z), you can take the floor or ceiling.