diff options
Diffstat (limited to 'theories/lambda/operational.v')
-rw-r--r-- | theories/lambda/operational.v | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/theories/lambda/operational.v b/theories/lambda/operational.v new file mode 100644 index 0000000..b0fa366 --- /dev/null +++ b/theories/lambda/operational.v | |||
@@ -0,0 +1,38 @@ | |||
1 | From mininix Require Export utils. | ||
2 | From stdpp Require Import options. | ||
3 | |||
4 | Module Import lambda. | ||
5 | |||
6 | Inductive expr := | ||
7 | | EString (s : string) | ||
8 | | EId (x : string) | ||
9 | | EAbs (x : string) (e : expr) | ||
10 | | EApp (e1 e2 : expr). | ||
11 | |||
12 | Fixpoint subst (ds : gmap string expr) (e : expr) : expr := | ||
13 | match e with | ||
14 | | EString s => EString s | ||
15 | | EId x => if ds !! x is Some d then d else EId x | ||
16 | | EAbs x e => EAbs x (subst (delete x ds) e) | ||
17 | | EApp e1 e2 => EApp (subst ds e1) (subst ds e2) | ||
18 | end. | ||
19 | |||
20 | Reserved Infix "-->" (right associativity, at level 55). | ||
21 | Inductive step : expr → expr → Prop := | ||
22 | | Sβ x e1 e2 : EApp (EAbs x e1) e2 --> subst {[x:=e2]} e1 | ||
23 | | SAppL e1 e1' e2 : e1 --> e1' → EApp e1 e2 --> EApp e1' e2 | ||
24 | where "e1 --> e2" := (step e1 e2). | ||
25 | |||
26 | Infix "-->*" := (rtc step) (right associativity, at level 55). | ||
27 | |||
28 | Definition final (e : expr) : Prop := | ||
29 | match e with | ||
30 | | EString _ => True | ||
31 | | EAbs _ _ => True | ||
32 | | _ => False | ||
33 | end. | ||
34 | |||
35 | Definition stuck (e : expr) : Prop := | ||
36 | nf step e ∧ ¬final e. | ||
37 | |||
38 | End lambda. | ||