File tree Expand file tree Collapse file tree 1 file changed +3
-36
lines changed Expand file tree Collapse file tree 1 file changed +3
-36
lines changed Original file line number Diff line number Diff line change 1
1
# Early and Late Bound Variables
2
2
3
- A generic type may be [ _ universally_ or _ existentially_ quantified] [ quant ] . For
4
- example,
5
-
6
- [ quant ] : ./appendix/background.md#quantified
7
-
8
- ``` rust,ignore
9
- fn foo<T>()
10
- ```
11
- This function claims that the function is well-typed for all types ` T ` . To use
12
- the chalk notation: ` forall<T> foo<T> ` .
13
-
14
- Another example:
15
-
16
- ``` rust,ignore
17
- fn foo<'a>(_: &'a usize)
18
- ```
19
- This function claims that there is some lifetime ` 'a ` (determined by the
20
- caller) such that it is well-typed.
21
-
22
- One more example:
23
-
24
- ``` rust,ignore
25
- fn foo<F>()
26
- where for<'a> F: Fn(&'a u8),
27
- ```
28
- This function claims that for all lifetimes ` 'a ` and types ` F ` satisfying the
29
- bound, it is well-typed:
30
-
31
- ``` txt
32
- forall<'a, F> {
33
- if F: Fn(&'a u8) {
34
- foo<'a, f>
35
- }
36
- }
37
- ```
38
-
3
+ In Rust, generic types are generally [ _ universally_ quantified] [ quant ] .
39
4
Notice, however, that in Rust, we don't have (at the language level)
40
5
universally quantified types; there is no ` forall<F> foo<F> ` in Rust. As a
41
6
result, we have a sort of weird split in how we represent some generic types:
42
7
_ early-_ and _ late-_ bound parameters.
43
8
9
+ [ quant ] : ./appendix/background.md#quantified
10
+
44
11
Basically, if we cannot represent a type (e.g. a universally quantified type),
45
12
we have to bind it _ early_ so that the unrepresentable type is never around.
46
13
You can’t perform that action at this time.
0 commit comments