forked from thanhnguyen-aws/plausible
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSTLCDefinitions.lean
More file actions
44 lines (40 loc) · 1.39 KB
/
STLCDefinitions.lean
File metadata and controls
44 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Plausible.Chamelean.DecOpt
import Plausible.Chamelean.Enumerators
import Plausible.Chamelean.EnumeratorCombinators
/-- Base types in the Simply-Typed Lambda Calculus (STLC)
(either Nat or functions) -/
inductive type where
| Nat : type
| Fun : type → type → type
deriving BEq, DecidableEq, Repr
/-- Terms in the STLC extended with naturals and addition -/
inductive term where
| Const: Nat → term
| Add: term → term → term
| Var: Nat → term
| App: term → term → term
| Abs: type → term → term
deriving BEq, Repr
/-- `lookup Γ n τ` checks whether the `n`th element of the context `Γ` has type `τ` -/
inductive lookup : List type -> Nat -> type -> Prop where
| Now : forall τ Γ, lookup (τ :: Γ) .zero τ
| Later : forall τ τ' n Γ,
lookup Γ n τ -> lookup (τ' :: Γ) (.succ n) τ
/-- `typing Γ e τ` is the typing judgement `Γ ⊢ e : τ` -/
inductive typing: List type → term → type → Prop where
| TConst : ∀ Γ n,
typing Γ (.Const n) .Nat
| TAdd: ∀ Γ e1 e2,
typing Γ e1 .Nat →
typing Γ e2 .Nat →
typing Γ (.Add e1 e2) .Nat
| TAbs: ∀ Γ e τ1 τ2,
typing (τ1::Γ) e τ2 →
typing Γ (.Abs τ1 e) (.Fun τ1 τ2)
| TVar: ∀ Γ x τ,
lookup Γ x τ →
typing Γ (.Var x) τ
| TApp: ∀ Γ e1 e2 τ1 τ2,
typing Γ e2 τ1 →
typing Γ e1 (.Fun τ1 τ2) →
typing Γ (.App e1 e2) τ2