Standard library
Which module to take for a task and how to import it. The library has 66 modules and 2284 functions. Every module has its own page: functions, their conditions and an example.
Modules by task
Text and parsing
| Module | What for |
|---|---|
| Strings | split, replace, trim, change case, pad a string |
| String lists | lists of strings: first, last, join, common prefix |
| String sets | a set of strings: union, intersection, difference |
| Automaton | regular expressions without backtracking |
| Parsing | parsing the text of your own small language |
| Samples | finding a word, a stem or a piece in a string without regex |
| CLI | command-line flags and arguments, the --help text |
| UTF-8 | text to UTF-8 bytes and back |
| Text decoding | bytes to text: UTF-8, UTF-16, UTF-32, CP1251, KOI8-R |
| Unicode normalization | Unicode normalization: NFC, NFD, NFKC, NFKD |
| Unicode graphemes | graphemes: the visible characters of a string and their count |
| Unicode case folding | case-insensitive string comparison by Unicode |
| Unicode tables | looking up a code point in the Unicode tables |
| Code page data | code page tables for CP1251 and KOI8-R |
| Unicode case data | Unicode data for case-insensitive comparison |
| Unicode grapheme data | Unicode data on grapheme boundaries |
| Unicode normalization data | Unicode data for normalization |
Numbers
| Module | What for |
|---|---|
| Numbers | sign, absolute value, GCD and LCM, power, factorial, digits |
| Bignum | integers of any size: arithmetic, comparison, decimal text |
| Rationals | exact fractions over big integers |
| Number format | printing a number in bases 2–16 and with a precision |
| Statistics | mean, median, mode, variance, quantile |
| Logic | and, or, not, implication, "all true" over a list |
Collections
| Module | What for |
|---|---|
| Lists | length, slice, search, sum, sorting of a list |
| Higher order | map, filter, reduce, sort with your own comparison |
| Optional | a value that may be absent (Optional) |
| Result | success with a value or an error with a reason (Result) |
| Dictionary | a small string → string map as a list of pairs |
| Hash map | a fast string → value map |
| Tree map | a string → string map as a search tree |
| Number tree | a search tree of numbers, sorting by traversal |
Time
| Module | What for |
|---|---|
| Date and time | dates and times: ISO-8601, addition, difference, weekdays |
Files and network
| Module | What for |
|---|---|
| Requests and responses | HTTP: parsing and printing requests and responses, URLs, headers |
| WebSocket | WebSocket: the upgrade answer and frames |
| DNS | DNS packets: parsing a response, building a query |
| Wire | bytes, network-order integers, cutting a stream into messages |
| Registry | a package registry as data: versions, ranges, dependencies |
Databases
| Module | What for |
|---|---|
| Postgres | the PostgreSQL 3.0 protocol: client and server messages |
| Redis | the Redis protocol (RESP 2): commands and replies |
| SQLite | an SQLite 3 database file: reading tables, building a file, inserting a row |
Cryptography
| Module | What for |
|---|---|
| SHA-256 | the SHA-256 hash |
| SHA-1 | SHA-1, HMAC-SHA1 and PBKDF2-HMAC-SHA1 for legacy protocols |
| HMAC | HMAC-SHA256 |
| Key derivation | a key from a password: PBKDF2-HMAC-SHA256 |
| SCRAM | SCRAM-SHA-256 password login, the client side |
| AES | AES-128 and AES-256 encryption: block, CTR, CBC, GCM |
| X25519 | X25519 key exchange |
| ECDSA | ECDSA signature verification on the P-256 curve |
| RSA signature | RSA signature verification: PKCS#1 v1.5 and PSS |
| DER | reading DER, the binary ASN.1 encoding |
| X.509 | reading an X.509 certificate out of PEM |
| Revocation list | certificate revocation lists (CRL) |
| Trust store | a store of root certificates |
| Certificate path | verifying a certificate chain up to a root |
| TLS records | TLS 1.3 records: format, keys, decryption |
| TLS handshake | the TLS 1.3 handshake: messages, Finished, certificates |
| TLS client | a TLS 1.3 client step by step: from ClientHello to the server response |
Formats
| Module | What for |
|---|---|
| JSON | JSON: parsing into a value and printing back |
| TOML | TOML configs: parsing, a value by path, printing |
| Base64 | Base64: the standard and the URL-safe alphabet |
| Protobuf | Protocol Buffers: the wire format without a schema |
| UUID | UUID: parsing, printing, versions 4 and 5 |
Lemmas for proofs
| Module | What for |
|---|---|
| Math classics | classical arithmetic lemmas from Coq and Lean |
| Math classics for lists | classical lemmas about lists from Coq and Lean |
| List facts | lemmas about lists for your own proofs |
| Fmath | claims about the lengths of lists and strings |
Importing a module
использует is the import. The module name is written in English, as in the catalogue above. No file path is needed.
File sum.flang:
модуль «Сумма до предела»
использует «Lists»
тотальная функция «Сумма чисел до предела»
принимает предел: число
возвращает число
пример «До пяти»
дано предел равно 5
ожидается 15
«Сумма» от («Числа до» от предел)
$ flang check sum.flang
модуль «Сумма до предела»: функций 39, из них с доказанным завершением 39; типов 1; файлов вместе с импортами 2
предупреждений 1: встроенная операция в тотальной функции может отказать при работе; код возврата они не меняют, с «--proof --strict» это ошибки
…
sum.flang: проверено — доказано 0, проверено только на тестах 0, не доказано 0 (постусловий и утверждений 0); замечаний нет
The first line counts functions together with the module: all functions of Lists and one of yours. The second is a warning about a function of the Lists module itself; it does not change the exit code. The last line is the result: there are no errors, and your file has no postconditions, so every counter is zero. The postconditions of the module are not counted here.
The tests of the module run with yours, so a program with a large module (AES, TLS client) takes a few minutes to check.
A module has no Russian name
Replace the module name in sum.flang with «Списки» ("lists" in Russian):
$ flang check sum.flang
…
FLANG_IMPORT_NOT_FOUND в файле sum.flang, строка 1, столбец 1: не найден модуль «Списки»: ни рядом с файлом, ни выше по каталогам, ни в библиотеке компилятора
FLANG_UNKNOWN_NAME в файле sum.flang, строка 10, столбец 3: неизвестная функция «Сумма»
…
sum.flang: не проверено — замечаний 5
There is no module «Списки»: lists are «Lists». The compiler says the module was not found next to the file, up the directories, or in its library. The использует line takes the English name.
A part of a module
The word только imports the named functions and the ones they call:
использует «Lists» только «Двоичный поиск»
With this line the program gets «Двоичный поиск» and the two functions it needs. The tests of the other Lists functions do not run, and the check is faster.
Running a program with a module
flang run evaluates one function. Before that it looks whether every postcondition of the program and of its modules is proved:
$ flang run sum.flang "«Сумма чисел до предела»" 5
не доказано: утверждений 66: доказано 42, сетка 24, на веру 0 — запуск только по явному согласию: --на-веру
…
$ flang run sum.flang "«Сумма чисел до предела»" 5 --trust
на веру: доказанность не считалась — запуск по ключу --trust
15
The first command stopped with exit code 3: of 66 postconditions 42 are proved (доказано) and 24 are checked on tests only (сетка). The --trust flag runs the program without this check; the unproved postconditions are then checked at run time.
How much is proved
A postcondition (обеспечивает) is a statement about the result of a function. The compiler proves it for any arguments. Where it could not, the postcondition is checked on the values from the tests and at run time.
| What is counted | How many |
|---|---|
| modules | 66 |
| functions | 2284 |
| postconditions | 3604 |
| of them proved | 674 |
| checked on tests only | 294 |
| not proved | 49 |
| status not measured for the current version of the module | 2587 |
The status of every postcondition is on the module page, next to the function. For your own program flang check sum.flang --proof prints the same report.
Next
- Modules and packages — your own module and a module by link.
- Why and how to prove — what "proved" means.
- Unicode text — normalization, graphemes, case.