-
Notifications
You must be signed in to change notification settings - Fork 0
/
redsem.txt
86 lines (53 loc) · 1.64 KB
/
redsem.txt
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
f,f',... ∈ OpSymbol
x,k,m,p,... ∈ Vars
e ::= v
| e e
| e!
| handle case* e e
| op f e* -- Algebraic effect
| ho f e* e* -- Higher-order effect
v ::= lam x e
| {e}
| c
| x
case ::= return x = e
| op f x* p k = e
| ho f x* m* p = e
E ::= E e | v E | E!
| handle cases E e | handle cases v E
| op f (E...e) | ... | op f (v...E)
| ho f (E...e) es | ... | ho f (v...E) es | ho f vs (E...e) | ho f vs (v...E)
e |-> e'
------------------
E[ e ] --> E[ e' ]
{e}! |-> e
(lam x e) v |-> e[x/v]
(return x p = e) ∈ cases
--------------------------------------
handle cases vp v |-> e[ x/v, p/vp ]
there are no closer handlers that match f in E
y, q are fresh
(op f xs p k = e) ∈ cases
-----------------------------------------------------------
handle cases vp E[ op f vs ]
|-> e[ xs/vs , p/vp , k/(λ y q . handle cases q E[y]) ]
there are no closer handlers that match f in E
(ho f xs ms p = e) ∈ cases
-------------------------------------------------------
handle cases vp E[ ho f vs vsm ]
|-> handle cases vp E[ e[ xs/vs , p/vp , ms/vsm ] ]
ALTERNATIVE
there are no closer handlers that match f in E
y, q are fresh
(op f xs ms p k = e) ∈ cases
-----------------------------------------------------------
handle cases vp E[ op f vs vsm ]
|-> e[ xs/vs , ms/vsm , p/vp , k/(λ y q . handle cases q E[y!]) ]
{-
handler hExc : {[Exc|e] a <h>} -> {[e] Maybe a <Exc|h>}
op catch p h k = k { match hExc p with Nothing -> h!
| Just x -> x }
| op throw k = Nothing
-----
k : {[Exc|e+h] a} -> [e] b
-}