The standard library
Import a module, find an operation in its source, and use the same collection at different universe levels.
Browse the standard library by module. Its Omegyu source is built into
the compiler. A module is imported by its name, as in std:List,
and is a record: std:List.map is one of its fields.
You can also store types in collections; see universe polymorphism.
There are no type classes. A function that compares elements takes the
comparison explicitly. Here sortBy orders numbers and lookup compares text keys:
{ sorted = std:List.sortBy std:Natural.lessThanEqual [ 3, 1, 2 ]
, age =
std:Map.lookup
Text/equal
"Ada"
(std:Map.fromList Text/equal [ { key = "Ada", value = 36 } ])
}Normal form
{ age = Some 36, sorted = [ 1, 2, 3 ] }Open the definition of lookup to read its parameters. To see
the type of the whole module, use omegyu type -e 'std:Map'.
General purpose
Transform each element with
List.map, or combine elements into one value withList.foldLeft.For keyed entries, use
std:Map; for membership alone, usestd:Set. Both take an equality test for the key.Use
std:Vecwhen the length must be part of the type. Usestd:Resultwhen failure should carry a reason.To print a line or read an argument, build an action with
std:IO. Running a program explains how to execute it.
For the rest, browse all modules or open std:Prelude to see which modules it collects.
Proofs and evidence
| Module | Contents |
|---|---|
std:Equal | sym, trans, cong, subst, cast |
std:Arith | arithmetic without axioms (proofs about numbers): the hypothesis NatFacts; the laws of + and *; the orders Le and Lt, with induction, monotonicity and cancellation; truncated subtraction; Euclidean division; the soundness of the comparisons of std:Natural; bridges from the words of Word 256 to naturals; case analyses |
std:Ring | polynomial identities by reflection: Expr, with var, const, add and mul, and eval, normalise, Poly, sound, ring and ringLe |
std:List/Law | the laws of the list eliminators that list fusion uses, and their corollaries, such as mapMap and foldMap |
std:Validation | predicates of validity: Valid, values paired with their evidence, Checked, and check, which gives evidence or errors for a computed input |
std:Certificate | proof-producing computation: make, Valid, prove, known, map, both, label |
std:Observation | pack a source for one designated Reader; view gets that reader's result, not the source |
std:Region | half-open regions, bounded locations, proofs of containment and disjointness, inspectable Plan values and proved automatic packing |
std:Reflection/… | Row, Structure, Interface, Table, Lens and Candidate: the shared types of reflection, and the adapters built on it |
Imports and contracts
| Module | Contents |
|---|---|
std:Import | the sources of imports: Source, Http, Header, Secret, Tls, file, std, env, get, post, request, http, header, bearer, defaultTls (imports) |
std:EVM/Contract | contracts with typed handler modes, Solidity and native interfaces, and composition (the EVM back end) |
std:EVM/Operations | separately importable operation signatures, checked public names and routes; independent of storage and implementation |
std:EVM/Effect | the modes, and the records of operations that actions receive (actions and modes) |
std:EVM/State/Layout | storage layouts with their proofs of validity (storage layout from types) |
std:EVM/… | the signature of the machine, its base monad, the run-time boundary, the Solidity markers, the native codec, immutables, the owners of storage, and Model, the reference model of the machine, which runs the term that the compiler compiles |
Universe polymorphism
The levels of the library's definitions are implicit arguments, found from
the types that the definitions are used at, as those of the builtins are.
The library is therefore used at Type 1 and above as it is used at
Type: a map can name types, a vector can hold them, and a computation can
keep them in its state.
let types =
std:Map.fromList
Text/equal
[ { key = "number", value = Natural }
, { key = "text", value = Text }
]
let Stack = List Type
let stack = std:State.monad Stack
let push = \(a : Type) -> std:State.modify (\(s : Stack) -> [ a ] # s)
in { number = std:Map.lookup Text/equal "number" types
, pushed =
std:State.exec
(do stack { push Natural; push Text })
([] : Stack)
, vector = std:Vec.cons Natural (std:Vec.cons Text std:Vec.nil)
}Normal form
{ number = Some Natural
, pushed = [ Text, Natural ]
, vector = ((Natural, (Text, {=})) : Type * (Type * unit @1))
}The types that the library defines take types of any universes, and live in the largest of them:
{ map = std:Map.Map
, set = std:Set.Set
, result = std:Result.Result
, state = std:State.State
, vec = std:Vec.Vec
, monad = std:Monad.Monad
}Type
{ map :
forall {lk lv : Level}
-> Type lk
-> Type lv
-> Type (Level/max lk lv)
, monad :
forall {l : Level}
-> (Type l -> Type l)
-> Type (Level/imax (l + 1) l)
, result :
forall {le la : Level}
-> Type le
-> Type la
-> Type (Level/max le la)
, set : forall {l : Level} -> Type l -> Type l
, state :
forall {ls la : Level}
-> Type ls
-> Type la
-> Type (Level/max ls la)
, vec : forall {l : Level} -> Type l -> Natural -> Type l
}A monad takes the types of one universe to types of the same universe.
std:Monad.optional, list and io are the monads of Optional, List
and IO at every level. The record of a monad on Type is a Type,
because Type is impredicative, and above it the record is one universe
up: hence the Level/imax.
std:IO.putStr, putStrLn, print and writeFile produce unit, as
IO/putStr and IO/writeFile do. So a step of a do block of
std:Monad.io @1, which produces a value of a type of Type 1, cannot
print. Follow the printing action with IO/pure {=}, or write the block
without a monad, as a plain do block, whose IO/bind joins actions of
any universes:
let io = std:Monad.io @1
in do io {
do { IO/putStr "x"; IO/pure {=} };
IO/pure Natural
}Type
IO Typelet io = std:Monad.io @1
in do io {
IO/putStr "x";
IO/pure Natural
}Error E0003
error[E0003]: type mismatch
┌─ example.omg:3:7
│
3 │ IO/putStr "x";
│ ^^^^^^^^^^^^^ this has type IO unit
│
= expected: IO _
actual: IO unit
= because the unknown type lives in Type 1, and unit lives in Type
= a record type lifted to a universe above the one of its fields, as `unit @l` is, has the same values as at any other level, but it is another type: there is no cumulativity
= help: give the value the type of its fields lifted to Type 1
where it is built, as in `({=} : unit @1)` or
`({ a = 1 } : { a : Natural, ...((| |) : Row (Type 1)) })`
= help: follow the action with one that produces the empty record of the universe that is expected: `do { action; IO/pure {=} }`