Documentation menu
Language

Programs and lexical structure

What an Omegyu source file holds, and how its text is read into comments, names, keywords, numbers, texts and symbols.

Find a section6 sections

Programs

A source file holds one expression. let names a value for the rest of the expression, and the expression after in is the result:

Normal form
let double = \(n : Natural) -> n * 2
in  double 21
Your result
Complete example · with imports

Normal form

42

Evaluating this expression produces 42 without any side effects. An interaction with the world is a value of type IO a; omegyu run carries it out. For recursive computations, totality shows how a function follows the structure of its input. The trust reference distinguishes proved normalisation results from assumptions about the full language.

Comments

-- starts a comment that runs to the end of the line. A block comment starts with {- and ends with -}, and block comments nest:

Normal form
-- A line comment.
{- A block comment, {- which nests -} -}
1 + 1 -- a comment at the end of a line
Your result
Complete example · with imports

Normal form

2

Names

A name starts with an ASCII letter or _, and goes on with ASCII letters, digits and _. Inside a name, - and / join two parts, as in is-empty and List/elim; a name does not end with them. A name written between backticks can hold any other character, such as a space or a letter outside ASCII:

Normal form
let `first name` = "Ada"
let is-empty = Text/equal ""
in  { `first name`, empty = is-empty `first name` }
Your result
Complete example · with imports

Normal form

{ empty = False, `first name` = "Ada" }

The keywords are let, in, if, then, else, forall, exists, merge, otherwise, assert, with, without, do and import. NaN and Infinity are number literals. To use one of these words as a name or as a label, write it between backticks: `in`.

The names of the builtins cannot be defined again, but they can be labels, as in { Natural = 2 }:

Rejected
let Natural = 1
in  Natural
Your result
Complete example · with imports

Error E0002

error[E0002]: `Natural` is a builtin and cannot be redefined
  ┌─ example.omg:1:5
  │
1 │ let Natural = 1
  │     ^^^^^^^ this name is reserved
  │
  = help: choose another name; builtins can still be used as record labels, e.g. `{ Natural = ... }`

Numbers

TypeLiterals
Natural0, 42, 0xff
Integera sign and a natural: +3, -3
Doublea fraction or an exponent: 1.5, -0.5, 6.02e23, and NaN and Infinity
Normal form
{ hex = 0xff, integer = -3, positive = +3, double = 6.02e23, nan = NaN }
Your result
Complete example · with imports

Normal form

{ double = 6.02e23, hex = 255, integer = -3, nan = NaN, positive = +3 }

A + or a - that a digit follows is the sign of a number, unless it touches what comes before it. n+1 and n + 1 are additions, and f +1 applies f to the integer +1:

Normal form
let f = \(i : Integer) -> Integer/add i +1
let n = 2
in  { sum = n+1, spaced = n + 1, applied = f +1 }
Your result
Complete example · with imports

Normal form

{ applied = +2, spaced = 3, sum = 3 }

A - that a space follows is an operator of other types. No operator subtracts naturals: Natural/subtract does.

Texts

A text literal is written between double quotes, on one line. ${e} inserts the value of an expression e of type Text. The escapes are \", \\, \$, \/, \n, \r, \t, \b, \f, \u followed by four hexadecimal digits, and \u{…} with up to eight hexadecimal digits:

Normal form
let n = 42
in  "tab\there, ${Natural/show n} \u{1F600} \$ \"q\""
Your result
Complete example · with imports

Normal form

"tab\there, 42 😀 $ \"q\""

A text literal that is not closed on its line is an error, E0103: write \n where a text has a line break. Sources are UTF-8, and a byte order mark at the start of a source is ignored.

Symbols

Some symbols also have a Unicode spelling, which means the same as the ASCII one:

ASCIIUnicodeASCIIUnicode
\λ===≡
->→<=≤
<-←>=≥
forall∀//⫽
exists∃/\∧
*×//\\⩓

omegyu format --unicode rewrites a source with the Unicode spellings, and the compiler reads both:

Normal form
λ(n : Natural) → n + 1
Your result
Complete example · with imports

Normal form

\(n : Natural) -> n + 1