Numeric types¶
Disco has four types which represent numbers:
Natural numbers, written
N
,ℕ
,Nat
, orNatural
. These represent the counting numbers 0, 1, 2, … which can be added and multiplied.Disco> :type 5 5 : ℕ
Integers, written
Z
,ℤ
,Int
, orInteger
, allow negative numbers such as-5
. They extend the natural numbers with subtraction.Disco> :type -5 -5 : ℤ
Fractional numbers, written
F
,𝔽
,Frac
, orFractional
, allow fractions like2/3
. They extend the natural numbers with division.Disco> :type 2/3 2 / 3 : 𝔽
Rational numbers, written
Q
,ℚ
, orRational
, 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
andQ
) can also be subtracted. - The types on the upper right of the diamond (
F
andQ
) can also be divided. - To move down and to the right (i.e. from
Z
toN
, or fromQ
toF
), you can use absolute value. - To move down and to the left (i.e. from
F
toN
, or fromQ
toZ
), you can take the floor or ceiling.