Skip to content

Commit 7b1934c

Browse files
Create type-system.md
1 parent 03f756d commit 7b1934c

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

type-system.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
## Lambda Calculus
2+
3+
Lambda Calculus just has variables, functions, and function applications.
4+
It is a "dynamic" language without static types.
5+
6+
```
7+
λx. x y z
8+
```
9+
10+
## Simply Typed Lambda Calculus
11+
12+
Types can help distinguish terms and their intended purpose.
13+
Each type is a simple name or an arrow.
14+
15+
```
16+
1 : Integer
17+
f : Integer -> Integer
18+
```
19+
20+
## System F
21+
22+
System F adds the ability for objects to be parameterized with quantified type variables.
23+
In LM type variables are represented with lowercase identifiers.
24+
25+
```
26+
some : a -> Option<a>
27+
```
28+
29+
## System F<:
30+
31+
System F<: adds the ability for objects to become subtypes (<:) of a hierarchical type system.
32+
33+
In standard notation this might look something like this:
34+
35+
```
36+
type X implies Y;
37+
38+
(x : X) <: Y # yes
39+
```
40+
41+
In plural notation the subtyping relations can often be expanded to clarify a bit more of what is going on.
42+
43+
```
44+
(x : X+Y) <: Y # yes
45+
```
46+
47+
## System F<: with Specialization
48+
49+
Specialization adds the ability to pun (overload) functions onto the same identifier.
50+
Then, when applied, punned functions are "narrowed as necessary" to decide which function to apply.
51+
52+
$$abstraction \quad \frac{\Gamma \vdash a:A \quad \Gamma \vdash b:B \quad \Gamma \vdash x:X \quad \Gamma \vdash y:Y \quad λ⟨a.b⟩⟨x.y⟩}{\Gamma \vdash λ⟨a.b⟩⟨x.y⟩:(A \to B) + (X \to Y)}$$
53+
54+
$$application \quad \frac{\Gamma \vdash f:(A \to B) + (C \to D) + (X \to Y) \quad \Gamma \vdash x:A + X \quad f(x)}{\Gamma \vdash f(x):B + Y}$$
55+
56+
## Logical Propositions
57+
58+
Nominal Types can be associated with logical properties.
59+
When a Type carries a proposition, in order to soundly fulfill that proposition two things need to be independently proven:
60+
1) The term carries the proposition's name (for example `List::Sorted`)
61+
2) The name is only given to terms that satisfy the proposition's semantic conditions (`List::Sorted` lists are sorted)
62+
63+
Condition 1 is already working in the type system, however condition 2 will require some significant work.
64+
This feature is a prerequisite for fully certified builds.
65+
66+
## Phi Types
67+
68+
Many novel type systems can be expressed as Phi Types.
69+
The term "Phi Type" comes from the more widely recognized Phi Functions in Single Static Assignment form.
70+
A Phi Function is used to merge variables coming from two separate parent code paths.
71+
A Phi Type is similarly used to merge types coming from two separate parent code paths.
72+
73+
Example:
74+
75+
$$\frac{if \quad condition \quad then \quad truecase \quad else \quad falsecase}{logically \quad merge \quad truecase \quad and \quad falsecase}$$
76+
77+
becomes
78+
79+
$$\frac{if \quad condition \quad then \quad truecase \quad else \quad falsecase}{φ(truecase,falsecase)}$$
80+
81+
so only a new phi function needs to be defined.
82+
83+
Phi types can also have state transitions decorated onto the inference graph.
84+
For example the `fclose` function will cause a state transition from `FileState::Open` to `FileState::Closed`.

0 commit comments

Comments
 (0)