Operators
The operators of the builtin types, from the loosest to the tightest, and the operators that a record in scope gives to other types.
Precedence
The table lists the operators from the loosest to the tightest, and all of
them associate to the left. Application binds tighter than every operator,
and selection with . binds tighter than application. -> and :, as in
A -> B and e : A, bind looser than every operator.
| Operator | Unicode | Meaning |
|---|---|---|
=== | ≡ | the type of the proofs of an equation |
|| | the disjunction of booleans | |
<= | ≤ | no builtin meaning |
>= | ≥ | no builtin meaning |
+ | the addition of naturals | |
- | no builtin meaning | |
++ | the concatenation of texts (the first join below) | |
# | the concatenation of lists | |
&& | the conjunction of booleans | |
/\ | ∧ | the recursive merge of records |
// | ⫽ | the right-biased merge of records |
//\\ | ⩓ | the recursive merge of record types |
* | × | the multiplication of naturals, and the product of types |
== | the equality of booleans | |
!= | the inequality of booleans |
{ product = 1 + 2 * 3
, both = True || False && False
, joined = "a" ++ "b" ++ "c"
}Normal form
{ both = True, joined = "abc", product = 7 }Natural/subtract subtracts naturals, and
records describes the merges.
Operators of other types
On a type other than the builtin ones, an operator is a field named after
it, of a record in scope. a - b is r.`-` a b, for the innermost
variable r whose type is a record with a field `-` that takes the
type of a. So are <= and >=, which have no builtin meaning, and +,
*, ==, !=, && and || where their builtin meaning does not apply:
on Natural, Bool and types, the operators mean what they always mean.
A number literal where such a type is expected is the field fromNatural
of such a record, applied to the number:
let Ops =
\(Num : Type) ->
{ `-` : Num -> Num -> Num, fromNatural : Natural -> Num }
let less = \(Num : Type) (o : Ops Num) (x : Num) -> x - 1
let integers
: Ops Integer
= { `-` = \(a b : Integer) -> Integer/add a (Integer/negate b)
, fromNatural = Natural/toInteger
}
in less Integer integers +5Normal form
+4In less, x - 1 is o.`-` x (o.fromNatural 1). Without such a record
in scope, the operator is an error:
let a = 3
in a - 1Error E0028
error[E0028]: no operator `-` for this type
┌─ example.omg:2:5
│
2 │ in a - 1
│ ^^^^^ this has type Natural
│
= an operator on a type other than the builtin ones is a field named after it, between backticks, of a record in scope: a variable whose type is a record with a field `-` that takes this type
= help: bring such a record in scope (a parameter, or a `let`), or apply a function instead
= help: on numbers, `Natural/subtract b a` is a - b, or 0 when b is larger