notation.v 5.23 KB
Newer Older
1 2
From iris.program_logic Require Import language.
From iris.heap_lang Require Export lang tactics.
3
Set Default Proof Using "Type*".
4

5
Coercion LitInt : Z >-> base_lit.
6
Coercion LitBool : bool >-> base_lit.
7 8
Coercion LitLoc : loc >-> base_lit.

9 10 11
Coercion App : expr >-> Funclass.
Coercion of_val : val >-> expr.

12 13
Coercion Var : string >-> expr.

14
Coercion BNamed : string >-> binder.
15
Notation "<>" := BAnon : binder_scope.
16

17 18
(* No scope for the values, does not conflict and scope is often not inferred
properly. *)
19 20
Notation "# l" := (LitV l%Z%V) (at level 8, format "# l").
Notation "# l" := (Lit l%Z%V) (at level 8, format "# l") : expr_scope.
21

22 23 24
(** Syntax inspired by Coq/Ocaml. Constructions with higher precedence come
    first. *)
Notation "( e1 , e2 , .. , en )" := (Pair .. (Pair e1 e2) .. en) : expr_scope.
Robbert Krebbers's avatar
Robbert Krebbers committed
25
Notation "( e1 , e2 , .. , en )" := (PairV .. (PairV e1 e2) .. en) : val_scope.
26
Notation "'match:' e0 'with' 'InjL' x1 => e1 | 'InjR' x2 => e2 'end'" :=
Ralf Jung's avatar
Ralf Jung committed
27
  (Match e0 x1%bind e1 x2%bind e2)
28
  (e0, x1, e1, x2, e2 at level 200) : expr_scope.
29
Notation "'match:' e0 'with' 'InjR' x1 => e1 | 'InjL' x2 => e2 'end'" :=
Ralf Jung's avatar
Ralf Jung committed
30
  (Match e0 x2%bind e2 x1%bind e1)
Ralf Jung's avatar
Ralf Jung committed
31
  (e0, x1, e1, x2, e2 at level 200, only parsing) : expr_scope.
32
Notation "()" := LitUnit : val_scope.
33 34 35 36 37 38 39 40 41 42 43 44
Notation "! e" := (Load e%E) (at level 9, right associativity) : expr_scope.
Notation "'ref' e" := (Alloc e%E)
  (at level 30, right associativity) : expr_scope.
Notation "- e" := (UnOp MinusUnOp e%E)
  (at level 35, right associativity) : expr_scope.
Notation "e1 + e2" := (BinOp PlusOp e1%E e2%E)
  (at level 50, left associativity) : expr_scope.
Notation "e1 - e2" := (BinOp MinusOp e1%E e2%E)
  (at level 50, left associativity) : expr_scope.
Notation "e1 ≤ e2" := (BinOp LeOp e1%E e2%E) (at level 70) : expr_scope.
Notation "e1 < e2" := (BinOp LtOp e1%E e2%E) (at level 70) : expr_scope.
Notation "e1 = e2" := (BinOp EqOp e1%E e2%E) (at level 70) : expr_scope.
45
Notation "e1 ≠ e2" := (UnOp NegOp (BinOp EqOp e1%E e2%E)) (at level 70) : expr_scope.
46
Notation "~ e" := (UnOp NegOp e%E) (at level 75, right associativity) : expr_scope.
47
(* The unicode ← is already part of the notation "_ ← _; _" for bind. *)
48
Notation "e1 <- e2" := (Store e1%E e2%E) (at level 80) : expr_scope.
Ralf Jung's avatar
Ralf Jung committed
49
Notation "'rec:' f x := e" := (Rec f%bind x%bind e%E)
50
  (at level 102, f at level 1, x at level 1, e at level 200) : expr_scope.
51
Notation "'rec:' f x := e" := (locked (RecV f%bind x%bind e%E))
52
  (at level 102, f at level 1, x at level 1, e at level 200) : val_scope.
53 54
Notation "'if:' e1 'then' e2 'else' e3" := (If e1%E e2%E e3%E)
  (at level 200, e1, e2, e3 at level 200) : expr_scope.
55 56 57 58 59

(** Derived notions, in order of declaration. The notations for let and seq
are stated explicitly instead of relying on the Notations Let and Seq as
defined above. This is needed because App is now a coercion, and these
notations are otherwise not pretty printed back accordingly. *)
Ralf Jung's avatar
Ralf Jung committed
60
Notation "'rec:' f x y := e" := (Rec f%bind x%bind (Lam y%bind e%E))
61
  (at level 102, f, x, y at level 1, e at level 200) : expr_scope.
62
Notation "'rec:' f x y := e" := (locked (RecV f%bind x%bind (Lam y%bind e%E)))
63
  (at level 102, f, x, y at level 1, e at level 200) : val_scope.
Ralf Jung's avatar
Ralf Jung committed
64
Notation "'rec:' f x y .. z := e" := (Rec f%bind x%bind (Lam y%bind .. (Lam z%bind e%E) ..))
65
  (at level 102, f, x, y, z at level 1, e at level 200) : expr_scope.
66
Notation "'rec:' f x y .. z := e" := (locked (RecV f%bind x%bind (Lam y%bind .. (Lam z%bind e%E) ..)))
67 68
  (at level 102, f, x, y, z at level 1, e at level 200) : val_scope.

Ralf Jung's avatar
Ralf Jung committed
69
Notation "λ: x , e" := (Lam x%bind e%E)
70
  (at level 102, x at level 1, e at level 200) : expr_scope.
Ralf Jung's avatar
Ralf Jung committed
71
Notation "λ: x y .. z , e" := (Lam x%bind (Lam y%bind .. (Lam z%bind e%E) ..))
72
  (at level 102, x, y, z at level 1, e at level 200) : expr_scope.
73
Notation "λ: x , e" := (locked (LamV x%bind e%E))
74
  (at level 102, x at level 1, e at level 200) : val_scope.
75
Notation "λ: x y .. z , e" := (locked (LamV x%bind (Lam y%bind .. (Lam z%bind e%E) .. )))
76
  (at level 102, x, y, z at level 1, e at level 200) : val_scope.
77

Ralf Jung's avatar
Ralf Jung committed
78
Notation "'let:' x := e1 'in' e2" := (Lam x%bind e2%E e1%E)
79 80 81
  (at level 102, x at level 1, e1, e2 at level 200) : expr_scope.
Notation "e1 ;; e2" := (Lam BAnon e2%E e1%E)
  (at level 100, e2 at level 200, format "e1  ;;  e2") : expr_scope.
82
(* These are not actually values, but we want them to be pretty-printed. *)
Ralf Jung's avatar
Ralf Jung committed
83
Notation "'let:' x := e1 'in' e2" := (LamV x%bind e2%E e1%E)
84
  (at level 102, x at level 1, e1, e2 at level 200) : val_scope.
85
Notation "e1 ;; e2" := (LamV BAnon e2%E e1%E)
86
  (at level 100, e2 at level 200, format "e1  ;;  e2") : val_scope.
87

88
(* Shortcircuit Boolean connectives *)
89
Notation "e1 && e2" :=
Robbert Krebbers's avatar
Oops.  
Robbert Krebbers committed
90
  (If e1%E e2%E (Lit (LitBool false))) (only parsing) : expr_scope.
91
Notation "e1 || e2" :=
Robbert Krebbers's avatar
Oops.  
Robbert Krebbers committed
92
  (If e1%E (Lit (LitBool true)) e2%E) (only parsing) : expr_scope.
93

94
(** Notations for option *)
95 96
Notation NONE := (InjL #()) (only parsing).
Notation SOME x := (InjR x) (only parsing).
97

98 99
Notation NONEV := (InjLV #()) (only parsing).
Notation SOMEV x := (InjRV x) (only parsing).
100 101 102

Notation "'match:' e0 'with' 'NONE' => e1 | 'SOME' x => e2 'end'" :=
  (Match e0 BAnon e1 x%bind e2)
103
  (e0, e1, x, e2 at level 200, only parsing) : expr_scope.
104
Notation "'match:' e0 'with' 'SOME' x => e2 | 'NONE' => e1 'end'" :=
105 106
  (Match e0 BAnon e1 x%bind e2)
  (e0, e1, x, e2 at level 200, only parsing) : expr_scope.