Skip to content

Commit dfe2659

Browse files
committed
Document notation
1 parent 420e937 commit dfe2659

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

book/src/glossary.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
22

33
This is a glossary of terminology (possibly) used in the chalk crate.
44

5+
## Notation
6+
7+
### Basic notation
8+
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 |
15+
16+
### Rules
17+
18+
- `forall<T> { (Vec<T>: Clone) :- (T: Clone)`: for every `T`, `Vec<T>`
19+
implements `Clone` if `T` implements `Clone`
20+
21+
### Queries
22+
23+
- `Vec<i32>: Clone`: does `Vec<i32>` implement `Clone`?
24+
- `exists<T> { Vec<T>: Clone }`: does there exist a `T` such that `Vec<T>`
25+
implements `Clone`?
26+
27+
[Type inference variable]: ../types/rust_types.md#inference-variables
28+
[Bound variable]: ../types/rust_types.md#bound-variables
29+
[Placeholder]: ../types/rust_types.md#placeholders
30+
[Clause]: ../clauses/goals_and_clauses.md
31+
532
## Binary connective
633
There are sixteen logical connectives on two boolean variables. The most
734
interesting in this context are listed below. There is also a truth table given
@@ -50,15 +77,15 @@ the optional positive literal. Due to the equivalence `(P => Q) <=> (!P || Q)`
5077
the clause can be expressed as `B && C && ... => A` which means that A is true
5178
if `B`, `C`, etc. are all true. All rules in chalk are in this form. For example
5279

53-
```notrust
80+
```rust,ignore
5481
struct A<T> {}
5582
impl<T> B for A<T> where T: C + D {}
5683
```
5784

5885
is expressed as the *Horn clause* `(T: C) && (T: D) => (A<T>: B)`. This formula
5986
has to hold for all values of `T`. The second example
6087

61-
```notrust
88+
```rust,ignore
6289
struct A {}
6390
impl B for A {}
6491
impl C for A {}
@@ -149,7 +176,7 @@ syntactic rules.
149176
In the context of the Rust type system this means that basic rules for type
150177
construction have to be met. Two examples: 1) Given a struct definition
151178

152-
```notrust
179+
```rust,ignore
153180
struct HashSet<T: Hash>
154181
```
155182
then a type `HashSet<i32>` is well-formed since `i32` implements `Hash`. A type

0 commit comments

Comments
 (0)