-
Notifications
You must be signed in to change notification settings - Fork 5
/
GoalMode.sml
65 lines (57 loc) · 2.29 KB
/
GoalMode.sml
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
structure GoalMode :> GOALMODE =
struct
open Syntax
open PatternNormalize
(* okGoal : nfAsyncType -> bool *)
fun okGoal ty =
case Util.nfTypePrjAbbrev ty of
TAtomic (_, _) => true
| TMonad A => okGoalSync (syncNormalize A)
| AddProd (A, B) => okGoal A andalso okGoal B
| TLPi (p, A, B) => let val (_, A') = tpatNormalize (p, A)
in
okChainSync A' andalso okGoal B
end
| TAbbrev _ => raise Fail "Internal error: okGoal TAbbrev"
(* okGoalSync : nfSyncType -> bool *)
and okGoalSync sty =
case NfSyncType.prj sty of
TOne => true
| LExists (p1, S1, S2)
=> (case (Pattern.prj p1, NfSyncType.prj S1) of
(PBang (SOME _), TBang _) => okGoalSync S2
| (_, _) => okGoal (sync2async S1) andalso okGoalSync S2)
| S => raise Fail "Internal error: okGoalSync: pattern not normalized"
(* isBchain : nfAsyncType -> bool *)
and isBchain ty =
case Util.nfTypePrjAbbrev ty of
TAtomic (_,_) => true
| AddProd (A, B) => isBchain A andalso isBchain B
| TLPi (p, A, B) => let val (_, A') = tpatNormalize (p, A)
in
isBchain B andalso okGoalSync A'
end
| TMonad _ => false
| _ => raise Fail "Internal error: isBchain TAbbrev"
(* isFchain : nfAsyncType -> bool *)
and isFchain ty =
case Util.nfTypePrjAbbrev ty of
TAtomic (_,_) => false
| AddProd (A, B) => isFchain A andalso isFchain B
| TLPi (p, A, B) => let val (_, A') = tpatNormalize (p, A)
in
isFchain B andalso okGoalSync A'
end
| TMonad A => okGoalSync (syncNormalize A)
| _ => raise Fail "Internal error: isFchain TAbbrev"
and okChain ty = isBchain ty orelse isFchain ty
(* okChainSync : nfSyncType -> bool *)
and okChainSync sty =
case NfSyncType.prj sty of
TOne => true
| LExists (p1, S1, S2)
=> (case (Pattern.prj p1, NfSyncType.prj S1) of
(PBang (SOME _), TBang _) => okChainSync S2
| (_, _) => okChain (sync2async S1) andalso okChainSync S2)
| _ => raise Fail "Internal error: okChainSync: pattern not normalized"
end