Types¶
Summary
A type is what a stage file or a methods file writes after a colon, such as ℝ₊₊ @ !ctrl in the declaration c : ℝ₊₊ @ !ctrl. Its components are sets, a role word, a perch word and the word !cnst, written with @ between them, and several sets in one type declare their intersection. This page lists the objects of a stage with the type that each declaration writes, the role words, the perch words and their marks, the reserved sets, the forms in which a set is written, and the limits of the language on a type. Every table is printed from the package's own tables, so the page states each type as the package reads it.
Relationship with other documents
Builds on — Stages §2: declarations and types, with a complete file; Symbol conventions §9: the punctuation of a declaration, the domains and the type words. Formal account — Appendix D of the Bellman calculus: the classification of a field by its perch, its role and its value domain. See also — Refusals: every refusal rule, with the smallest example that breaks it; Rules and their code: the rules of the language beside the functions that check them.
1 What a type is¶
A declaration is a name, a colon and a type. In c : ℝ₊₊ @ !ctrl the name is c and the type is ℝ₊₊ @ !ctrl. A type has up to four kinds of component, written in any order with @ between them.
- A set states the values that the name may take. Several sets in one type declare their intersection:
β : (0,1) @ (0, R^(ρ-1))declares a discount factor that lies in both intervals. - A role word states what the name is in the decision problem: a state, a control, a value or a shock.
- A perch word states the perch at which the name stands, one of the three information sets of a stage.
- The word
!cnststates that a value-type field is a constant: its value and its declared set depend on no state, shock or control. It is written with the role word!vlu, as inL : (-inf, 0] @ !vlu @ !cnst(Stages §3.1).
A type holds at most one role word and at most one perch word. The components that a declaration writes depend on the object that it declares: a parameter is declared with sets alone, while a field has a set, a role and a perch.
2 The tables¶
§2.1 lists the objects of a stage. For each object it gives a line that declares it, taken from an application of the repository, the type which that line writes, the class of the record in which the package holds the object once the file is read, and the expression that reads the object from the stage object.
§2.2 to §2.4 list the words of a type: the role words, the perch words with the mark that a name carries for each perch, and the sets that the grammar reserves.
§2.5 lists the forms in which a set is written. The constructor of a form is the name that the abstract grammar of the language gives it (ASDL). Each row gives a declaration that writes the form, the set that the form holds, and the objects in whose type the package reads it.
§2.6 lists the limits of the language on a type. A refusal is the package's answer to a file that it does not read, and it names the rule that the file breaks (Refusals §1). Each row gives a line that breaks the limit and the rule of its refusal.
2.1 Objects of a stage¶
Each line stands in a file of the repository and is quoted without its annotation, the part of a line after ::. The files are applications/consumption-perfect-foresight-crra/declaration/stages/perfect_foresight/perfect_foresight.bl, applications/buffer-stock/declaration/stages/buffer_stock/buffer_stock.bl and applications/consumption-perfect-foresight-crra/declaration/stages/perfect_foresight/methods.egm.bl. A record is named by its module, as a path under packages/bellman/bellman/, and its class. The expression in the last column is written for the stage that the file states; where the line stands in a methods file, the stage has that methods file read.
2.2 Role words¶
A role word follows ! among the components of a type, as in c : ℝ₊₊ @ !ctrl. A field that carries no role word is a state, and the subject of a line that states a law with ~ is a shock. A multiplier takes no role word: a line inside a block declares it together with its clause, as μ[>] : ℝ₊ ⟂ a >= 0 does (Constraints §4.2).
| role | word |
|---|---|
| state | !state |
| control | !ctrl |
| value | !vlu |
| shock | !shck |
| multiplier | — |
2.3 Perch words and marks¶
A perch word follows ! after a side of a block header, as in (k : Xa) : !arvl. A mark is written directly after a name and states the perch of that one field. A name at the decision perch is written without a mark, and V[~] is read as V.
| perch | word | mark on a name |
|---|---|---|
| arrival | !arvl |
V[<] |
| decision | !dcsn |
none: V |
| continuation | !cntn |
V[>] |
2.4 Reserved sets¶
The grammar reserves these names, and a file writes one without defining it. Symbol conventions §9.2 says what each set holds.
| set | also written | kind of number | interval |
|---|---|---|---|
ℝ |
— | real | (-inf, inf) |
ℝ₊ |
R_{+}, R+ |
real | [0, inf) |
ℝ₊₊ |
R_{++}, R++ |
real | (0, inf) |
ℤ |
— | integer | — |
ℕ |
— | integer | — |
ℝ̄ |
— | extended real | — |
ℝ_{+∞} |
— | extended real | — |
ℝ_{-∞} |
— | extended real | — |
ℝ_{±∞} |
— | extended real | — |
2.5 Forms of a set expression¶
The last column names the objects of §2.1 in whose type the package reads the form. A field is taken there as a block header lists it, and §2.6 states what a declaration on a line of its own reads.
| constructor | written | what it holds | read in the type of |
|---|---|---|---|
Named |
R : ℝ₊₊ |
The set of that name: a reserved set of the language, here the strictly positive real numbers, or a set that the file defines after :=, Xa := ℝ₊. |
every object that is declared with a set |
Interval |
ρ : (1, inf) |
The real numbers between two endpoints, where a round bracket leaves its endpoint out and a square bracket includes it; an endpoint may read parameters, and -inf or inf leaves a side unbounded; an endpoint that is the bare name of a parameter or of a derived parameter which the calibration values at an infinity is read as that infinity. |
every object that is declared with a set |
FiniteSet |
d : {work, retire} |
The labels listed, which carry no arithmetic. | field, shock, parameter, setting and function |
Product |
x : ℝ × ℝ |
The ordered tuples that take one component from each factor. | field, shock, parameter, setting and function |
Comprehension |
θ : ℤ @ [1, inf) |
The members of one set that satisfy every condition stated, here the integers of at least one; several sets in one type are kept in this form, and a named set writes it with braces after :=, H := {i : ℤ | i >= 0, i <= 1}. |
shock, parameter, derived parameter and setting |
IntegerRange |
j : {1, …, 5} |
Every integer from the first bound to the second, both included; a bound may read parameters, and ... is a second spelling of …. |
every object that is declared with a set |
Points |
s : {0, 1} |
The integers listed, in the order written; a list in which a member reads a parameter names the set its members lie in, {0, θ} ⊂ ℤ. |
every object that is declared with a set |
Functions |
δ : {1, …, 5} → ℝ |
The collections that hold one entry of the second set for each member of the finite index set. A function-valued constant may also have a continuous domain. | field, shock, parameter, setting and function |
SetUnion |
ρ : (0,1) \/ (1, inf) |
The numbers that lie in at least one of the sets; ∪ is a second spelling of \/. |
parameter, derived parameter and setting |
SetDifference |
ρ : ℝ₊₊ \ {1} |
The numbers of the first set that the second does not hold; ∖ is a second spelling of \. |
parameter, derived parameter and setting |
2.6 Limits on a type¶
The package refuses each line below, in a stage file that holds no other declaration, under the rule beside it.
| limit | a line that breaks it | refusal |
|---|---|---|
| Several sets in one type are one set of numbers and the intervals that bound it, so at most one of them is written otherwise than as an interval; a named set counts as such a set. | θ : ℤ @ ℝ₊₊ |
syntax |
The several sets of one type have a number in common, which the package decides from the endpoints that are numbers or ratios of two integers, 1/3. |
β : (0,1) @ (2,3) |
syntax |
| Several sets in one type restrict one declared name, and no declaration of several names carries them. | (w, c) : ℝ @ (0, 1) |
syntax |
| Several sets are read on a declaration that stands on a line of its own; a field listed on a block header and an argument of a function carry one set each. | 𝑓(x : ℝ₊ @ (0, 1)) := x^2 |
readable-form |
| A union and a difference are formed among sets of numbers; a set of labels, a product and a set of functions are no members of one. | β : {a, b} \/ (0, 1) |
syntax |
| A union and a difference are read in the set of a parameter, of a derived parameter and of a setting; the set of a field, of a shock and of an argument of a function holds neither. | c : ℝ₊₊ \ {1} @ !ctrl |
readable-form |
The value of a named set, written after :=, is no union and no difference. |
Xρ := (0,1) \/ (1, inf) |
syntax |
| The value of a named set holds no union and no difference inside it either, such as the set of the entries of a collection. | Xq := {1, …, 2} → ℝ \ {0} |
readable-form |
| A definition that declares a set reads at least one name; a value that reads none is a number, which the calibration supplies. | ρ : ℝ := 2 |
readable-form |
| A formula by cases may stand on the right side of an equation or of a derived parameter definition, including as a nested branch. A declared set endpoint admits no formula by cases. | x : (0, if 1 < 2 then 1 else 2) |
syntax |
In a derived parameter's definition inf and -inf stand only as a whole branch of a definition by cases; a definition that reads a name valued at an infinity where it is evaluated, in a formula, a call or a test, as the branch that its test chooses or as its whole right side, has no value at that calibration, and neither has a bound of a declared set that computes with such a name; a bound that computes with the written inf, (0, 2*inf), has none at any calibration; a bound that calls a function other than log, exp, min and max is not decided, whatever it computes with. |
x := 2*inf |
derived-parameter |
The words if, then and else are words of the language and no names. |
if : ℝ₊₊ |
syntax |
A branch written inf or -inf stands in a definition whose declared set can hold that infinity, and the set ℝ of a definition that declares none holds neither. |
h := if 1 < 2 then 1 else inf |
derived-parameter |