author | huffman |
Fri, 08 May 2009 16:19:51 -0700 | |
changeset 31076 | 99fe356cbbc2 |
parent 31023 | d027411c9a38 |
child 31162 | 6dc708ca4a8f |
permissions | -rw-r--r-- |
23152 | 1 |
(* Title: HOLCF/Tools/domain/domain_library.ML |
2 |
Author: David von Oheimb |
|
3 |
||
4 |
Library for domain command. |
|
5 |
*) |
|
6 |
||
7 |
||
8 |
(* ----- general support ---------------------------------------------------- *) |
|
9 |
||
10 |
fun mapn f n [] = [] |
|
11 |
| mapn f n (x::xs) = (f n x) :: mapn f (n+1) xs; |
|
12 |
||
13 |
fun foldr'' f (l,f2) = let fun itr [] = raise Fail "foldr''" |
|
14 |
| itr [a] = f2 a |
|
15 |
| itr (a::l) = f(a, itr l) |
|
16 |
in itr l end; |
|
30190 | 17 |
fun map_cumulr f start xs = List.foldr (fn (x,(ys,res))=>case f(x,res) of (y,res2) => |
23152 | 18 |
(y::ys,res2)) ([],start) xs; |
19 |
||
20 |
||
21 |
fun first (x,_,_) = x; fun second (_,x,_) = x; fun third (_,_,x) = x; |
|
22 |
fun upd_first f (x,y,z) = (f x, y, z); |
|
23 |
fun upd_second f (x,y,z) = ( x, f y, z); |
|
24 |
fun upd_third f (x,y,z) = ( x, y, f z); |
|
25 |
||
27239 | 26 |
fun atomize ctxt thm = let val r_inst = read_instantiate ctxt; |
23152 | 27 |
fun at thm = case concl_of thm of |
28 |
_$(Const("op &",_)$_$_) => at(thm RS conjunct1)@at(thm RS conjunct2) |
|
27231 | 29 |
| _$(Const("All" ,_)$Abs(s,_,_))=> at(thm RS (r_inst [(("x", 0), "?" ^ s)] spec)) |
23152 | 30 |
| _ => [thm]; |
31 |
in map zero_var_indexes (at thm) end; |
|
32 |
||
31006 | 33 |
(* infix syntax *) |
34 |
||
35 |
infixr 5 -->; |
|
36 |
infixr 6 ->>; |
|
37 |
infixr 0 ===>; |
|
38 |
infixr 0 ==>; |
|
39 |
infix 0 ==; |
|
40 |
infix 1 ===; |
|
41 |
infix 1 ~=; |
|
42 |
infix 1 <<; |
|
43 |
infix 1 ~<<; |
|
44 |
||
45 |
infix 9 ` ; |
|
46 |
infix 9 `% ; |
|
47 |
infix 9 `%%; |
|
48 |
||
49 |
||
23152 | 50 |
(* ----- specific support for domain ---------------------------------------- *) |
51 |
||
31006 | 52 |
signature DOMAIN_LIBRARY = |
53 |
sig |
|
54 |
val Imposs : string -> 'a; |
|
55 |
val pcpo_type : theory -> typ -> bool; |
|
56 |
val string_of_typ : theory -> typ -> string; |
|
57 |
||
58 |
(* Creating HOLCF types *) |
|
59 |
val mk_cfunT : typ * typ -> typ; |
|
60 |
val ->> : typ * typ -> typ; |
|
61 |
val mk_ssumT : typ * typ -> typ; |
|
62 |
val mk_sprodT : typ * typ -> typ; |
|
63 |
val mk_uT : typ -> typ; |
|
64 |
val oneT : typ; |
|
65 |
val trT : typ; |
|
66 |
val mk_maybeT : typ -> typ; |
|
67 |
val mk_ctupleT : typ list -> typ; |
|
68 |
val mk_TFree : string -> typ; |
|
69 |
val pcpoS : sort; |
|
70 |
||
71 |
(* Creating HOLCF terms *) |
|
72 |
val %: : string -> term; |
|
73 |
val %%: : string -> term; |
|
74 |
val ` : term * term -> term; |
|
75 |
val `% : term * string -> term; |
|
76 |
val /\ : string -> term -> term; |
|
77 |
val UU : term; |
|
78 |
val TT : term; |
|
79 |
val FF : term; |
|
80 |
val mk_up : term -> term; |
|
81 |
val mk_sinl : term -> term; |
|
82 |
val mk_sinr : term -> term; |
|
83 |
val mk_stuple : term list -> term; |
|
84 |
val mk_ctuple : term list -> term; |
|
85 |
val mk_fix : term -> term; |
|
86 |
val mk_iterate : term * term * term -> term; |
|
87 |
val mk_fail : term; |
|
88 |
val mk_return : term -> term; |
|
89 |
val cproj : term -> 'a list -> int -> term; |
|
90 |
val list_ccomb : term * term list -> term; |
|
91 |
val con_app : string -> ('a * 'b * string) list -> term; |
|
92 |
val con_app2 : string -> ('a -> term) -> 'a list -> term; |
|
93 |
val proj : term -> 'a list -> int -> term; |
|
94 |
val prj : ('a -> 'b -> 'a) -> ('a -> 'b -> 'a) -> 'a -> 'b list -> int -> 'a; |
|
95 |
val mk_ctuple_pat : term list -> term; |
|
96 |
val mk_branch : term -> term; |
|
97 |
||
98 |
(* Creating propositions *) |
|
99 |
val mk_conj : term * term -> term; |
|
100 |
val mk_disj : term * term -> term; |
|
101 |
val mk_imp : term * term -> term; |
|
102 |
val mk_lam : string * term -> term; |
|
103 |
val mk_all : string * term -> term; |
|
104 |
val mk_ex : string * term -> term; |
|
105 |
val mk_constrain : typ * term -> term; |
|
106 |
val mk_constrainall : string * typ * term -> term; |
|
107 |
val === : term * term -> term; |
|
108 |
val << : term * term -> term; |
|
109 |
val ~<< : term * term -> term; |
|
110 |
val strict : term -> term; |
|
111 |
val defined : term -> term; |
|
112 |
val mk_adm : term -> term; |
|
113 |
val mk_compact : term -> term; |
|
114 |
val lift : ('a -> term) -> 'a list * term -> term; |
|
115 |
val lift_defined : ('a -> term) -> 'a list * term -> term; |
|
116 |
||
117 |
(* Creating meta-propositions *) |
|
118 |
val mk_trp : term -> term; (* HOLogic.mk_Trueprop *) |
|
119 |
val == : term * term -> term; |
|
120 |
val ===> : term * term -> term; |
|
121 |
val ==> : term * term -> term; |
|
122 |
val mk_All : string * term -> term; |
|
123 |
||
124 |
(* Domain specifications *) |
|
125 |
type arg = (bool * int * DatatypeAux.dtyp) * string option * string; |
|
126 |
type cons = string * arg list; |
|
127 |
type eq = (string * typ list) * cons list; |
|
128 |
val is_lazy : arg -> bool; |
|
129 |
val rec_of : arg -> int; |
|
130 |
val sel_of : arg -> string option; |
|
131 |
val vname : arg -> string; |
|
132 |
val upd_vname : (string -> string) -> arg -> arg; |
|
133 |
val is_rec : arg -> bool; |
|
134 |
val is_nonlazy_rec : arg -> bool; |
|
135 |
val nonlazy : arg list -> string list; |
|
136 |
val nonlazy_rec : arg list -> string list; |
|
137 |
val %# : arg -> term; |
|
138 |
val /\# : arg * term -> term; |
|
139 |
val when_body : cons list -> (int * int -> term) -> term; |
|
140 |
val when_funs : 'a list -> string list; |
|
141 |
val bound_arg : ''a list -> ''a -> term; (* ''a = arg or string *) |
|
142 |
val idx_name : 'a list -> string -> int -> string; |
|
143 |
val app_rec_arg : (int -> term) -> arg -> term; |
|
144 |
||
145 |
(* Name mangling *) |
|
146 |
val strip_esc : string -> string; |
|
147 |
val extern_name : string -> string; |
|
148 |
val dis_name : string -> string; |
|
149 |
val mat_name : string -> string; |
|
150 |
val pat_name : string -> string; |
|
151 |
val mk_var_names : string list -> string list; |
|
152 |
end; |
|
153 |
||
31023 | 154 |
structure Domain_Library :> DOMAIN_LIBRARY = |
31006 | 155 |
struct |
23152 | 156 |
|
157 |
exception Impossible of string; |
|
158 |
fun Imposs msg = raise Impossible ("Domain:"^msg); |
|
159 |
||
160 |
(* ----- name handling ----- *) |
|
161 |
||
162 |
val strip_esc = let fun strip ("'" :: c :: cs) = c :: strip cs |
|
163 |
| strip ["'"] = [] |
|
164 |
| strip (c :: cs) = c :: strip cs |
|
165 |
| strip [] = []; |
|
166 |
in implode o strip o Symbol.explode end; |
|
167 |
||
168 |
fun extern_name con = case Symbol.explode con of |
|
169 |
("o"::"p"::" "::rest) => implode rest |
|
170 |
| _ => con; |
|
171 |
fun dis_name con = "is_"^ (extern_name con); |
|
172 |
fun dis_name_ con = "is_"^ (strip_esc con); |
|
173 |
fun mat_name con = "match_"^ (extern_name con); |
|
174 |
fun mat_name_ con = "match_"^ (strip_esc con); |
|
175 |
fun pat_name con = (extern_name con) ^ "_pat"; |
|
176 |
fun pat_name_ con = (strip_esc con) ^ "_pat"; |
|
177 |
||
178 |
(* make distinct names out of the type list, |
|
179 |
forbidding "o","n..","x..","f..","P.." as names *) |
|
180 |
(* a number string is added if necessary *) |
|
181 |
fun mk_var_names ids : string list = let |
|
182 |
fun nonreserved s = if s mem ["n","x","f","P"] then s^"'" else s; |
|
183 |
fun index_vnames(vn::vns,occupied) = |
|
184 |
(case AList.lookup (op =) occupied vn of |
|
185 |
NONE => if vn mem vns |
|
186 |
then (vn^"1") :: index_vnames(vns,(vn,1) ::occupied) |
|
187 |
else vn :: index_vnames(vns, occupied) |
|
188 |
| SOME(i) => (vn^(string_of_int (i+1))) |
|
189 |
:: index_vnames(vns,(vn,i+1)::occupied)) |
|
190 |
| index_vnames([],occupied) = []; |
|
191 |
in index_vnames(map nonreserved ids, [("O",0),("o",0)]) end; |
|
192 |
||
30910 | 193 |
fun pcpo_type sg t = Sign.of_sort sg (Sign.certify_typ sg t, @{sort pcpo}); |
26939
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents:
26012
diff
changeset
|
194 |
fun string_of_typ sg = Syntax.string_of_typ_global sg o Sign.certify_typ sg; |
23152 | 195 |
|
196 |
(* ----- constructor list handling ----- *) |
|
197 |
||
31006 | 198 |
type arg = |
199 |
(bool * int * DatatypeAux.dtyp) * (* (lazy,recursive element or ~1) *) |
|
200 |
string option * (* selector name *) |
|
201 |
string; (* argument name *) |
|
202 |
||
203 |
type cons = |
|
204 |
string * (* operator name of constr *) |
|
205 |
arg list; (* argument list *) |
|
206 |
||
207 |
type eq = |
|
208 |
(string * (* name of abstracted type *) |
|
209 |
typ list) * (* arguments of abstracted type *) |
|
210 |
cons list; (* represented type, as a constructor list *) |
|
23152 | 211 |
|
212 |
fun rec_of arg = second (first arg); |
|
213 |
fun is_lazy arg = first (first arg); |
|
214 |
val sel_of = second; |
|
215 |
val vname = third; |
|
216 |
val upd_vname = upd_third; |
|
217 |
fun is_rec arg = rec_of arg >=0; |
|
218 |
fun is_nonlazy_rec arg = is_rec arg andalso not (is_lazy arg); |
|
219 |
fun nonlazy args = map vname (filter_out is_lazy args); |
|
220 |
fun nonlazy_rec args = map vname (List.filter is_nonlazy_rec args); |
|
221 |
||
222 |
(* ----- support for type and mixfix expressions ----- *) |
|
223 |
||
30910 | 224 |
fun mk_uT T = Type(@{type_name "u"}, [T]); |
225 |
fun mk_cfunT (T, U) = Type(@{type_name "->"}, [T, U]); |
|
226 |
fun mk_sprodT (T, U) = Type(@{type_name "**"}, [T, U]); |
|
227 |
fun mk_ssumT (T, U) = Type(@{type_name "++"}, [T, U]); |
|
228 |
val oneT = @{typ one}; |
|
229 |
val trT = @{typ tr}; |
|
230 |
||
231 |
val op ->> = mk_cfunT; |
|
232 |
||
233 |
fun mk_TFree s = TFree ("'" ^ s, @{sort pcpo}); |
|
23152 | 234 |
|
235 |
(* ----- support for term expressions ----- *) |
|
236 |
||
237 |
fun %: s = Free(s,dummyT); |
|
238 |
fun %# arg = %:(vname arg); |
|
239 |
fun %%: s = Const(s,dummyT); |
|
240 |
||
241 |
local open HOLogic in |
|
242 |
val mk_trp = mk_Trueprop; |
|
243 |
fun mk_conj (S,T) = conj $ S $ T; |
|
244 |
fun mk_disj (S,T) = disj $ S $ T; |
|
245 |
fun mk_imp (S,T) = imp $ S $ T; |
|
246 |
fun mk_lam (x,T) = Abs(x,dummyT,T); |
|
247 |
fun mk_all (x,P) = HOLogic.mk_all (x,dummyT,P); |
|
248 |
fun mk_ex (x,P) = mk_exists (x,dummyT,P); |
|
24680 | 249 |
val mk_constrain = uncurry TypeInfer.constrain; |
250 |
fun mk_constrainall (x,typ,P) = %%:"All" $ (TypeInfer.constrain (typ --> boolT) (mk_lam(x,P))); |
|
23152 | 251 |
end |
252 |
||
253 |
fun mk_All (x,P) = %%:"all" $ mk_lam(x,P); (* meta universal quantification *) |
|
254 |
||
255 |
infixr 0 ===>; fun S ===> T = %%:"==>" $ S $ T; |
|
256 |
infixr 0 ==>; fun S ==> T = mk_trp S ===> mk_trp T; |
|
257 |
infix 0 ==; fun S == T = %%:"==" $ S $ T; |
|
258 |
infix 1 ===; fun S === T = %%:"op =" $ S $ T; |
|
259 |
infix 1 ~=; fun S ~= T = HOLogic.mk_not (S === T); |
|
31076
99fe356cbbc2
rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents:
31023
diff
changeset
|
260 |
infix 1 <<; fun S << T = %%: @{const_name Porder.below} $ S $ T; |
23152 | 261 |
infix 1 ~<<; fun S ~<< T = HOLogic.mk_not (S << T); |
262 |
||
30595
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
263 |
infix 9 ` ; fun f ` x = %%: @{const_name Rep_CFun} $ f $ x; |
23152 | 264 |
infix 9 `% ; fun f`% s = f` %: s; |
265 |
infix 9 `%%; fun f`%%s = f` %%:s; |
|
26012 | 266 |
|
30595
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
267 |
fun mk_adm t = %%: @{const_name adm} $ t; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
268 |
fun mk_compact t = %%: @{const_name compact} $ t; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
269 |
val ID = %%: @{const_name ID}; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
270 |
fun mk_strictify t = %%: @{const_name strictify}`t; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
271 |
fun mk_cfst t = %%: @{const_name cfst}`t; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
272 |
fun mk_csnd t = %%: @{const_name csnd}`t; |
26012 | 273 |
(*val csplitN = "Cprod.csplit";*) |
274 |
(*val sfstN = "Sprod.sfst";*) |
|
275 |
(*val ssndN = "Sprod.ssnd";*) |
|
30595
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
276 |
fun mk_ssplit t = %%: @{const_name ssplit}`t; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
277 |
fun mk_sinl t = %%: @{const_name sinl}`t; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
278 |
fun mk_sinr t = %%: @{const_name sinr}`t; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
279 |
fun mk_sscase (x, y) = %%: @{const_name sscase}`x`y; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
280 |
fun mk_up t = %%: @{const_name up}`t; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
281 |
fun mk_fup (t,u) = %%: @{const_name fup} ` t ` u; |
26012 | 282 |
val ONE = @{term ONE}; |
283 |
val TT = @{term TT}; |
|
284 |
val FF = @{term FF}; |
|
30595
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
285 |
fun mk_iterate (n,f,z) = %%: @{const_name iterate} $ n ` f ` z; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
286 |
fun mk_fix t = %%: @{const_name fix}`t; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
287 |
fun mk_return t = %%: @{const_name Fixrec.return}`t; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
288 |
val mk_fail = %%: @{const_name Fixrec.fail}; |
26012 | 289 |
|
30595
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
290 |
fun mk_branch t = %%: @{const_name Fixrec.branch} $ t; |
26012 | 291 |
|
292 |
val pcpoS = @{sort pcpo}; |
|
293 |
||
23152 | 294 |
val list_ccomb = Library.foldl (op `); (* continuous version of list_comb *) |
295 |
fun con_app2 con f args = list_ccomb(%%:con,map f args); |
|
296 |
fun con_app con = con_app2 con %#; |
|
297 |
fun if_rec arg f y = if is_rec arg then f (rec_of arg) else y; |
|
298 |
fun app_rec_arg p arg = if_rec arg (fn n => fn x => (p n)`x) I (%# arg); |
|
299 |
fun prj _ _ x ( _::[]) _ = x |
|
300 |
| prj f1 _ x (_::y::ys) 0 = f1 x y |
|
301 |
| prj f1 f2 x (y:: ys) j = prj f1 f2 (f2 x y) ys (j-1); |
|
302 |
fun proj x = prj (fn S => K(%%:"fst" $S)) (fn S => K(%%:"snd" $S)) x; |
|
26012 | 303 |
fun cproj x = prj (fn S => K(mk_cfst S)) (fn S => K(mk_csnd S)) x; |
23152 | 304 |
fun lift tfn = Library.foldr (fn (x,t)=> (mk_trp(tfn x) ===> t)); |
305 |
||
30595
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
306 |
fun /\ v T = %%: @{const_name Abs_CFun} $ mk_lam(v,T); |
23152 | 307 |
fun /\# (arg,T) = /\ (vname arg) T; |
30595
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
308 |
infixr 9 oo; fun S oo T = %%: @{const_name cfcomp}`S`T; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
309 |
val UU = %%: @{const_name UU}; |
23152 | 310 |
fun strict f = f`UU === UU; |
311 |
fun defined t = t ~= UU; |
|
30595
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
312 |
fun cpair (t,u) = %%: @{const_name cpair}`t`u; |
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
313 |
fun spair (t,u) = %%: @{const_name spair}`t`u; |
23152 | 314 |
fun mk_ctuple [] = HOLogic.unit (* used in match_defs *) |
315 |
| mk_ctuple ts = foldr1 cpair ts; |
|
26012 | 316 |
fun mk_stuple [] = ONE |
23152 | 317 |
| mk_stuple ts = foldr1 spair ts; |
318 |
fun mk_ctupleT [] = HOLogic.unitT (* used in match_defs *) |
|
319 |
| mk_ctupleT Ts = foldr1 HOLogic.mk_prodT Ts; |
|
320 |
fun mk_maybeT T = Type ("Fixrec.maybe",[T]); |
|
30595
c87a3350f5a9
proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents:
30190
diff
changeset
|
321 |
fun cpair_pat (p1,p2) = %%: @{const_name cpair_pat} $ p1 $ p2; |
26012 | 322 |
val mk_ctuple_pat = foldr1 cpair_pat; |
23152 | 323 |
fun lift_defined f = lift (fn x => defined (f x)); |
324 |
fun bound_arg vns v = Bound(length vns -find_index_eq v vns -1); |
|
325 |
||
326 |
fun cont_eta_contract (Const("Cfun.Abs_CFun",TT) $ Abs(a,T,body)) = |
|
327 |
(case cont_eta_contract body of |
|
328 |
body' as (Const("Cfun.Rep_CFun",Ta) $ f $ Bound 0) => |
|
329 |
if not (0 mem loose_bnos f) then incr_boundvars ~1 f |
|
330 |
else Const("Cfun.Abs_CFun",TT) $ Abs(a,T,body') |
|
331 |
| body' => Const("Cfun.Abs_CFun",TT) $ Abs(a,T,body')) |
|
332 |
| cont_eta_contract(f$t) = cont_eta_contract f $ cont_eta_contract t |
|
333 |
| cont_eta_contract t = t; |
|
334 |
||
335 |
fun idx_name dnames s n = s^(if length dnames = 1 then "" else string_of_int n); |
|
336 |
fun when_funs cons = if length cons = 1 then ["f"] |
|
337 |
else mapn (fn n => K("f"^(string_of_int n))) 1 cons; |
|
338 |
fun when_body cons funarg = let |
|
339 |
fun one_fun n (_,[] ) = /\ "dummy" (funarg(1,n)) |
|
340 |
| one_fun n (_,args) = let |
|
341 |
val l2 = length args; |
|
26012 | 342 |
fun idxs m arg = (if is_lazy arg then (fn t => mk_fup (ID, t)) |
23152 | 343 |
else I) (Bound(l2-m)); |
344 |
in cont_eta_contract (foldr'' |
|
26012 | 345 |
(fn (a,t) => mk_ssplit (/\# (a,t))) |
23152 | 346 |
(args, |
347 |
fn a=> /\#(a,(list_ccomb(funarg(l2,n),mapn idxs 1 args)))) |
|
348 |
) end; |
|
349 |
in (if length cons = 1 andalso length(snd(hd cons)) <= 1 |
|
26012 | 350 |
then mk_strictify else I) |
351 |
(foldr1 mk_sscase (mapn one_fun 1 cons)) end; |
|
23152 | 352 |
end; (* struct *) |