Skip to content

Commit ecdaf84

Browse files
committed
User doc
1 parent 2b7f808 commit ecdaf84

1 file changed

Lines changed: 40 additions & 7 deletions

File tree

user_manual.md

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ Note the following declarations generate terms of the same type:
201201
(declare-const Array_v3 (-> Type Type Type))
202202
```
203203

204-
<a name="literals"></a>
204+
<a name="tcdefine"></a>
205205

206206
### The :type attribute for definitions
207207

@@ -240,12 +240,10 @@ In general, an argument can be made implicit if its value can be inferred from t
240240

241241
Return types cannot be marked `:implicit` or `:var` or a type error will be immediately reported.
242242

243-
We call `T` in the above definitions a _parameter_. The free parameters of the return type of an expression should be contained in at least one non-implicit argument. In particular, the following declaration is malformed, since the return type of `f` cannot be inferred from its arguments:
244-
245-
```smt
246-
(declare-type Int ())
247-
(declare-const f (-> (! Type :var T :implicit) Int T))
248-
```
243+
We call `T` in the above definitions a _parameter_.
244+
Typically, the free parameters of the return type of a function should be contained in an explicit argument.
245+
If not, the function is considered *ambiguous* and requires an annotation with the SMT-LIB syntax `as`.
246+
For details, see [ambiguous functions](#amb-functions).
249247

250248
> __Note:__ Internally, `(! T :var t)` is syntax sugar for the type `(Quote t)` where `t` is a parameter of type `T` and `Quote` is a distinguished type of kind `(-> (! Type :var U) U Type)`. When type checking applications of functions of type `(-> (Quote t) S)`, the parameter `t` is bound to the argument the function is applied to.
251249
@@ -574,6 +572,38 @@ Furthermore, note that a binder also may accept an explicit term as its first ar
574572
In the above example, `Q4` has `(@cons x)` as its first argument, where `x` was explicitly defined as a variable.
575573
This means that the definition of `Q4` is also syntactically equivalent to the definition of `Q1` and `Q2`.
576574

575+
<a name="amb-functions"></a>
576+
577+
### Ambiguous Functions
578+
579+
Functions and constants that are declared via the command `declare-parameterized-const` may have return types that contain free parameters.
580+
If these parameters are *not* contained in any explicit argument to the function, then the function or constant is considered *ambiguous*.
581+
For example, consider a generic definition of the empty set:
582+
583+
```smt
584+
(declare-type Set (Type))
585+
(declare-parameterized-const set.empty ((T Type :implicit)) (Set T))
586+
587+
(declare-type Int ())
588+
(define f () (as set.empty (Set Int)) :type (Set Int))
589+
```
590+
591+
Above, set is declared as a parameteric type.
592+
The empty set has an implicit type argument `T` and has return type `(Set T)`.
593+
Since `T` is a free parameter, and `set.empty` has no implicit arguments, it is an ambiguous function.
594+
All uses of ambiguous functions must use the SMT-LIB syntax `as`,
595+
which expects the symbol to annotate and the return type of that instance.
596+
Above, `(as set.empty (Set Int))` refers to the instance of `set.empty` that has type `(Set Int)`.
597+
598+
The type of all ambiguous functions is automatically extended with an opaque type argument.
599+
600+
> __Note:__ Internally, type of all ambiguous functions is automatically extended with an opaque type argument.
601+
In the above example, `set.empty` is internally defined to be of type `(-> (Quote (Set T)) (Set T))`.
602+
Ethos interprets `(as set.empty (Set Int))` as `(_ set.empty (Set Int))`, where this is an "opaque" application (see [opaque](#opaque)).
603+
Conceptually, this means that `(_ set.empty (Set Int))` is a constant symbol (with no children) that is indexed by its type.
604+
605+
A similar treatment is given to ambiguous datatype constructors, which we describe later in [parameteric datatypes](#par-datatypes).
606+
577607
<a name="literals"></a>
578608

579609
### Literal types
@@ -1230,6 +1260,9 @@ Applying the proof rule `dt-split` to a variable `x` of type `Tree` allows us to
12301260
Note that the definitino of `dt-split` is applicable to *any* datatype definition.
12311261
In particular, as a second example, we see the rule applied to a term `y` of type `Color` gives us a conclusion with three disjuncts.
12321262

1263+
1264+
<a name="par-datatypes"></a>
1265+
12331266
### Parametric datatypes
12341267

12351268
Ethos supports reasoning about parametric datatypes with ambiguous datatype construtors using the same syntax as SMT-LIB 2.6.

0 commit comments

Comments
 (0)