37 |
39 |
38 (*******************************************) |
40 (*******************************************) |
39 fun lam2comb (Abs(x,tp,Bound 0)) _ = |
41 fun lam2comb (Abs(x,tp,Bound 0)) _ = |
40 let val tpI = Type("fun",[tp,tp]) |
42 let val tpI = Type("fun",[tp,tp]) |
41 in |
43 in |
|
44 include_min_comb:=true; |
42 Const("COMBI",tpI) |
45 Const("COMBI",tpI) |
43 end |
46 end |
44 | lam2comb (Abs(x,t1,Const(c,t2))) _ = |
47 | lam2comb (Abs(x,t1,Const(c,t2))) _ = |
45 let val tK = Type("fun",[t2,Type("fun",[t1,t2])]) |
48 let val tK = Type("fun",[t2,Type("fun",[t1,t2])]) |
46 in |
49 in |
|
50 include_min_comb:=true; |
47 Const("COMBK",tK) $ Const(c,t2) |
51 Const("COMBK",tK) $ Const(c,t2) |
48 end |
52 end |
49 | lam2comb (Abs(x,t1,Free(v,t2))) _ = |
53 | lam2comb (Abs(x,t1,Free(v,t2))) _ = |
50 let val tK = Type("fun",[t2,Type("fun",[t1,t2])]) |
54 let val tK = Type("fun",[t2,Type("fun",[t1,t2])]) |
51 in |
55 in |
|
56 include_min_comb:=true; |
52 Const("COMBK",tK) $ Free(v,t2) |
57 Const("COMBK",tK) $ Free(v,t2) |
53 end |
58 end |
54 | lam2comb (Abs(x,t1,Var(ind,t2))) _= |
59 | lam2comb (Abs(x,t1,Var(ind,t2))) _= |
55 let val tK = Type("fun",[t2,Type("fun",[t1,t2])]) |
60 let val tK = Type("fun",[t2,Type("fun",[t1,t2])]) |
56 in |
61 in |
|
62 include_min_comb:=true; |
57 Const("COMBK",tK) $ Var(ind,t2) |
63 Const("COMBK",tK) $ Var(ind,t2) |
58 end |
64 end |
59 | lam2comb (t as (Abs(x,t1,P$(Bound 0)))) Bnds = |
65 | lam2comb (t as (Abs(x,t1,P$(Bound 0)))) Bnds = |
60 let val nfreeP = not(is_free P 0) |
66 let val nfreeP = not(is_free P 0) |
61 val tr = Term.type_of1(t1::Bnds,P) |
67 val tr = Term.type_of1(t1::Bnds,P) |
65 let val tI = Type("fun",[t1,t1]) |
71 let val tI = Type("fun",[t1,t1]) |
66 val P' = lam2comb (Abs(x,t1,P)) Bnds |
72 val P' = lam2comb (Abs(x,t1,P)) Bnds |
67 val tp' = Term.type_of1(Bnds,P') |
73 val tp' = Term.type_of1(Bnds,P') |
68 val tS = Type("fun",[tp',Type("fun",[tI,tr])]) |
74 val tS = Type("fun",[tp',Type("fun",[tI,tr])]) |
69 in |
75 in |
|
76 include_min_comb:=true; |
|
77 include_combS:=true; |
70 Const("COMBS",tS) $ P' $ Const("COMBI",tI) |
78 Const("COMBS",tS) $ P' $ Const("COMBI",tI) |
71 end) |
79 end) |
72 end |
80 end |
73 |
81 |
74 | lam2comb (t as (Abs(x,t1,P$Q))) Bnds = |
82 | lam2comb (t as (Abs(x,t1,P$Q))) Bnds = |
77 in |
85 in |
78 if(nfreeP andalso nfreeQ) then ( |
86 if(nfreeP andalso nfreeQ) then ( |
79 let val tK = Type("fun",[tpq,Type("fun",[t1,tpq])]) |
87 let val tK = Type("fun",[tpq,Type("fun",[t1,tpq])]) |
80 val PQ' = decre_bndVar(P $ Q) |
88 val PQ' = decre_bndVar(P $ Q) |
81 in |
89 in |
|
90 include_min_comb:=true; |
82 Const("COMBK",tK) $ PQ' |
91 Const("COMBK",tK) $ PQ' |
83 end) |
92 end) |
84 else ( |
93 else ( |
85 if nfreeP then ( |
94 if nfreeP then ( |
86 let val Q' = lam2comb (Abs(x,t1,Q)) Bnds |
95 let val Q' = lam2comb (Abs(x,t1,Q)) Bnds |
87 val P' = decre_bndVar P |
96 val P' = decre_bndVar P |
88 val tp = Term.type_of1(Bnds,P') |
97 val tp = Term.type_of1(Bnds,P') |
89 val tq' = Term.type_of1(Bnds, Q') |
98 val tq' = Term.type_of1(Bnds, Q') |
90 val tB = Type("fun",[tp,Type("fun",[tq',Type("fun",[t1,tpq])])]) |
99 val tB = Type("fun",[tp,Type("fun",[tq',Type("fun",[t1,tpq])])]) |
91 in |
100 in |
|
101 include_min_comb:=true; |
92 Const("COMBB",tB) $ P' $ Q' |
102 Const("COMBB",tB) $ P' $ Q' |
93 end) |
103 end) |
94 else ( |
104 else ( |
95 if nfreeQ then ( |
105 if nfreeQ then ( |
96 let val P' = lam2comb (Abs(x,t1,P)) Bnds |
106 let val P' = lam2comb (Abs(x,t1,P)) Bnds |
97 val Q' = decre_bndVar Q |
107 val Q' = decre_bndVar Q |
98 val tq = Term.type_of1(Bnds,Q') |
108 val tq = Term.type_of1(Bnds,Q') |
99 val tp' = Term.type_of1(Bnds, P') |
109 val tp' = Term.type_of1(Bnds, P') |
100 val tC = Type("fun",[tp',Type("fun",[tq,Type("fun",[t1,tpq])])]) |
110 val tC = Type("fun",[tp',Type("fun",[tq,Type("fun",[t1,tpq])])]) |
101 in |
111 in |
|
112 include_min_comb:=true; |
102 Const("COMBC",tC) $ P' $ Q' |
113 Const("COMBC",tC) $ P' $ Q' |
103 end) |
114 end) |
104 else( |
115 else( |
105 let val P' = lam2comb (Abs(x,t1,P)) Bnds |
116 let val P' = lam2comb (Abs(x,t1,P)) Bnds |
106 val Q' = lam2comb (Abs(x,t1,Q)) Bnds |
117 val Q' = lam2comb (Abs(x,t1,Q)) Bnds |
107 val tp' = Term.type_of1(Bnds,P') |
118 val tp' = Term.type_of1(Bnds,P') |
108 val tq' = Term.type_of1(Bnds,Q') |
119 val tq' = Term.type_of1(Bnds,Q') |
109 val tS = Type("fun",[tp',Type("fun",[tq',Type("fun",[t1,tpq])])]) |
120 val tS = Type("fun",[tp',Type("fun",[tq',Type("fun",[t1,tpq])])]) |
110 in |
121 in |
|
122 include_min_comb:=true; |
|
123 include_combS:=true; |
111 Const("COMBS",tS) $ P' $ Q' |
124 Const("COMBS",tS) $ P' $ Q' |
112 end))) |
125 end))) |
113 end |
126 end |
114 | lam2comb (t as (Abs(x,t1,_))) _ = raise LAM2COMB (t); |
127 | lam2comb (t as (Abs(x,t1,_))) _ = raise LAM2COMB (t); |
115 |
128 |