Skip to content

Commit d3ff2e2

Browse files
committed
Explain bound variables some more
1 parent fe18075 commit d3ff2e2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

book/src/glossary.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ This is a glossary of terminology (possibly) used in the chalk crate.
66

77
### Basic notation
88

9-
| Notation | Meaning |
10-
|--------------|----------------------------------|
11-
| `?0` | [Type inference variable] |
12-
| `^0`, `^1.0` | [Bound variable] |
13-
| `!0` | [Placeholder] |
14-
| `A :- B` | [Clause]; A is true if B is true |
9+
| Notation | Meaning |
10+
|--------------|-----------------------------------------|
11+
| `?0` | [Type inference variable] |
12+
| `^0`, `^1.0` | [Bound variable]; bound in a [`forall`] |
13+
| `!0`, `!1.0` | [Placeholder] |
14+
| `A :- B` | [Clause]; A is true if B is true |
1515

1616
### Rules
1717

@@ -26,6 +26,7 @@ This is a glossary of terminology (possibly) used in the chalk crate.
2626

2727
[Type inference variable]: ../types/rust_types.md#inference-variables
2828
[Bound variable]: ../types/rust_types.md#bound-variables
29+
[`forall`]: #debruijn-index
2930
[Placeholder]: ../types/rust_types.md#placeholders
3031
[Clause]: ../clauses/goals_and_clauses.md
3132

@@ -103,6 +104,11 @@ Given the example `forall<T> { exists<U> { T: Foo<Item=U> } }` the
103104
literal names `U` and `T` are replaced with `0` and `1` respectively and the names are erased from the binders: `forall<_>
104105
{ exists<_> { 1: Foo<Item=0> } }`.
105106

107+
As another example, in `forall<X, Y> { forall <Z> { X } }`, `X` is represented
108+
as `^1.0`. The `1` represents the de Bruijn index of the variable and the `0`
109+
represents the index in that scope: `X` is bound in the second scope counting
110+
from where it is referenced, and it is the first variable bound in that scope.
111+
106112
## Formula
107113
A formula is a logical expression consisting of literals and constants connected
108114
by logical operators.

0 commit comments

Comments
 (0)