src/HOLCF/domain/library.ML
author paulson
Wed, 27 Nov 1996 10:40:45 +0100
changeset 2238 c72a23bbe762
parent 1834 c780a4f39454
child 2276 3eb9a113029e
permissions -rw-r--r--
Eta-expanded some declarations that are illegal under value polymorphism
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
     1
(* library.ML
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
     2
   Author : David von Oheimb
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
     3
   Created: 18-Jul-95 extracted from syntax.ML, axioms.ML, extender.ML, interface.ML
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
     4
   Updated: 30-Aug-95
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
     5
   Updated: 20-Oct-95 small improvement for atomize
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
     6
   Copyright 1995 TU Muenchen
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
     7
*)
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
     8
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
     9
(* ----- general support ---------------------------------------------------- *)
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    10
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    11
fun Id x = x;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    12
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    13
fun mapn f n []      = []
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    14
|   mapn f n (x::xs) = (f n x) :: mapn f (n+1) xs;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    15
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    16
fun foldr'' f (l,f2) = let fun itr []  = raise LIST "foldr''"
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    17
			     | itr [a] = f2 a
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    18
			     | itr (a::l) = f(a, itr l)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    19
in  itr l  end;
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    20
fun foldr' f l = foldr'' f (l,Id);
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    21
fun map_cumulr f start xs = foldr (fn (x,(ys,res))=>case f(x,res) of (y,res2) =>
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    22
						  (y::ys,res2)) (xs,([],start));
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    23
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    24
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    25
fun first  (x,_,_) = x; fun second (_,x,_) = x; fun third  (_,_,x) = x;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    26
fun upd_first  f (x,y,z) = (f x,   y,   z);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    27
fun upd_second f (x,y,z) = (  x, f y,   z);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    28
fun upd_third  f (x,y,z) = (  x,   y, f z);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    29
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    30
fun atomize thm = let val r_inst = read_instantiate;
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    31
    fun at  thm = case concl_of thm of
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    32
      _$(Const("op &",_)$_$_)       => at(thm RS conjunct1)@at(thm RS conjunct2)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    33
    | _$(Const("All" ,_)$Abs(s,_,_))=> at(thm RS (r_inst [("x","?"^s)] spec))
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    34
    | _				    => [thm];
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    35
in map zero_var_indexes (at thm) end;
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    36
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    37
(* ----- specific support for domain ---------------------------------------- *)
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    38
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    39
structure Domain_Library = struct
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    40
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    41
exception Impossible of string;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    42
fun Imposs msg = raise Impossible ("Domain:"^msg);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    43
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    44
(* ----- name handling ----- *)
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    45
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    46
val strip_esc = let fun strip ("'" :: c :: cs) = c :: strip cs
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    47
		    |   strip ["'"] = []
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    48
		    |   strip (c :: cs) = c :: strip cs
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    49
		    |   strip [] = [];
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    50
in implode o strip o explode end;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    51
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    52
fun extern_name con = case explode con of 
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    53
		   ("o"::"p"::" "::rest) => implode rest
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    54
		   | _ => con;
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    55
fun dis_name  con = "is_"^ (extern_name con);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    56
fun dis_name_ con = "is_"^ (strip_esc   con);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    57
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    58
(* make distinct names out of the type list, 
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    59
   forbidding "o", "x..","f..","P.." as names *)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    60
(* a number string is added if necessary *)
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    61
fun mk_var_names types : string list = let
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    62
    fun typid (Type  (id,_)   ) = hd     (explode id)
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    63
      | typid (TFree (id,_)   ) = hd (tl (explode id))
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    64
      | typid (TVar ((id,_),_)) = hd (tl (explode id));
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    65
    fun nonreserved id = let val cs = explode id in
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    66
			 if not(hd cs mem ["x","f","P"]) then id
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    67
			 else implode(chr(1+ord (hd cs))::tl cs) end;
1819
245721624c8d minor fix of index_vnames: name "O" is occupied (used in HOL/Relation.thy)
oheimb
parents: 1637
diff changeset
    68
    fun index_vnames(vn::vns,occupied) =
245721624c8d minor fix of index_vnames: name "O" is occupied (used in HOL/Relation.thy)
oheimb
parents: 1637
diff changeset
    69
          (case assoc(occupied,vn) of
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    70
             None => if vn mem vns
1819
245721624c8d minor fix of index_vnames: name "O" is occupied (used in HOL/Relation.thy)
oheimb
parents: 1637
diff changeset
    71
                     then (vn^"1") :: index_vnames(vns,(vn,1)  ::occupied)
245721624c8d minor fix of index_vnames: name "O" is occupied (used in HOL/Relation.thy)
oheimb
parents: 1637
diff changeset
    72
                     else  vn      :: index_vnames(vns,          occupied)
245721624c8d minor fix of index_vnames: name "O" is occupied (used in HOL/Relation.thy)
oheimb
parents: 1637
diff changeset
    73
           | Some(i) => (vn^(string_of_int (i+1)))
245721624c8d minor fix of index_vnames: name "O" is occupied (used in HOL/Relation.thy)
oheimb
parents: 1637
diff changeset
    74
				   :: index_vnames(vns,(vn,i+1)::occupied))
245721624c8d minor fix of index_vnames: name "O" is occupied (used in HOL/Relation.thy)
oheimb
parents: 1637
diff changeset
    75
      | index_vnames([],occupied) = [];
245721624c8d minor fix of index_vnames: name "O" is occupied (used in HOL/Relation.thy)
oheimb
parents: 1637
diff changeset
    76
in index_vnames(map (nonreserved o typid) types,[("O",0),("o",0)]) end;
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    77
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    78
fun type_name_vars (Type(name,typevars)) = (name,typevars)
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    79
|   type_name_vars _                     = Imposs "library:type_name_vars";
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    80
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    81
(* ----- constructor list handling ----- *)
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    82
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    83
type cons = (string *			(* operator name of constr *)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    84
	    ((bool*int)*		(*  (lazy,recursive element or ~1) *)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    85
	      string*			(*   selector name    *)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    86
	      string)			(*   argument name    *)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    87
	    list);			(* argument list      *)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    88
type eq = (string *		(* name      of abstracted type *)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    89
	   typ list) *		(* arguments of abstracted type *)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    90
	  cons list;		(* represented type, as a constructor list *)
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    91
2238
c72a23bbe762 Eta-expanded some declarations that are illegal under value polymorphism
paulson
parents: 1834
diff changeset
    92
fun rec_of arg  = snd (first arg);
c72a23bbe762 Eta-expanded some declarations that are illegal under value polymorphism
paulson
parents: 1834
diff changeset
    93
fun is_lazy arg = fst (first arg);
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    94
val sel_of    =       second;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    95
val     vname =       third;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    96
val upd_vname =   upd_third;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    97
fun is_rec         arg = rec_of arg >=0;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
    98
fun is_nonlazy_rec arg = is_rec arg andalso not (is_lazy arg);
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
    99
fun nonlazy     args   = map vname (filter_out is_lazy    args);
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   100
fun nonlazy_rec args   = map vname (filter is_nonlazy_rec args);
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   101
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   102
(* ----- support for type and mixfix expressions ----- *)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   103
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   104
fun mk_tvar s = TFree("'"^s,["pcpo"]);
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   105
fun mk_typ t (S,T) = Type(t,[S,T]);
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   106
infixr 5 -->;
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   107
infixr 6 ~>; val op ~> = mk_typ "->";
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   108
val NoSyn' = ThyOps.Mixfix NoSyn;
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   109
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   110
(* ----- support for term expressions ----- *)
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   111
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   112
fun % s = Free(s,dummyT);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   113
fun %# arg = %(vname arg);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   114
fun %% s = Const(s,dummyT);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   115
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   116
local open HOLogic in
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   117
val mk_trp = mk_Trueprop;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   118
fun mk_conj (S,T) = conj $ S $ T;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   119
fun mk_disj (S,T) = disj $ S $ T;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   120
fun mk_imp  (S,T) = imp  $ S $ T;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   121
fun mk_lam  (x,T) = Abs(x,dummyT,T);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   122
fun mk_all  (x,P) = HOLogic.mk_all (x,dummyT,P);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   123
local 
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   124
		    fun tf (Type (s,args)) = foldl (op $) (%s,map tf args)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   125
		    |   tf (TFree(s,_   )) = %s
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   126
		    |   tf _              = Imposs "mk_constrainall";
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   127
in
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   128
fun mk_constrain      (typ,T) = %%"_constrain" $ T $ tf typ;
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   129
fun mk_constrainall (x,typ,P) = %%"All" $ (%%"_constrainAbs" $ mk_lam(x,P) $ tf typ);
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   130
end;
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   131
			
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   132
fun mk_ex   (x,P) = mk_exists (x,dummyT,P);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   133
fun mk_not     P  = Const("not" ,boolT --> boolT) $ P;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   134
end;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   135
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   136
fun mk_All  (x,P) = %%"all" $ mk_lam(x,P); (* meta universal quantification *)
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   137
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   138
infixr 0 ===>;fun S ===> T = %%"==>" $ S $ T;
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   139
infixr 0 ==>;fun S ==> T = mk_trp S ===> mk_trp T;
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   140
infix 0 ==;  fun S ==  T = %%"==" $ S $ T;
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   141
infix 1 ===; fun S === T = %%"op =" $ S $ T;
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   142
infix 1 ~=;  fun S ~=  T = mk_not (S === T);
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   143
infix 1 <<;  fun S <<  T = %%"op <<" $ S $ T;
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   144
infix 1 ~<<; fun S ~<< T = mk_not (S << T);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   145
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   146
infix 9 `  ; fun f`  x = %%"fapp" $ f $ x;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   147
infix 9 `% ; fun f`% s = f` % s;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   148
infix 9 `%%; fun f`%%s = f` %%s;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   149
fun mk_cfapp (F,As) = foldl (op `) (F,As);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   150
fun con_app2 con f args = mk_cfapp(%%con,map f args);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   151
fun con_app con = con_app2 con %#;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   152
fun if_rec  arg f y   = if is_rec arg then f (rec_of arg) else y;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   153
fun app_rec_arg p arg = if_rec arg (fn n => fn x => (p n)`x) Id (%# arg);
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   154
fun prj _  _  y 1 _ = y
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   155
|   prj f1 _  y _ 0 = f1 y
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   156
|   prj f1 f2 y i j = prj f1 f2 (f2 y) (i-1) (j-1);
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   157
val cproj    = prj (fn S => %%"cfst"`S) (fn S => %%"csnd"`S);
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   158
val  proj    = prj (fn S => %%"fst" $S) (fn S => %%"snd" $S);
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   159
fun lift tfn = foldr (fn (x,t)=> (mk_trp(tfn x) ===> t));
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   160
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   161
fun /\ v T = %%"fabs" $ mk_lam(v,T);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   162
fun /\# (arg,T) = /\ (vname arg) T;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   163
infixr 9 oo; fun S oo T = %%"cfcomp"`S`T;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   164
val UU = %%"UU";
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   165
fun strict f = f`UU === UU;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   166
fun defined t = t ~= UU;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   167
fun cpair (S,T) = %%"cpair"`S`T;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   168
fun lift_defined f = lift (fn x => defined (f x));
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   169
fun bound_arg vns v = Bound(length vns-find(v,vns)-1);
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   170
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   171
fun cont_eta_contract (Const("fabs",TT) $ Abs(a,T,body)) = 
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   172
      (case cont_eta_contract body  of
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   173
        body' as (Const("fapp",Ta) $ f $ Bound 0) => 
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   174
	  if not (0 mem loose_bnos f) then incr_boundvars ~1 f 
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   175
	  else   Const("fabs",TT) $ Abs(a,T,body')
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   176
      | body' => Const("fabs",TT) $ Abs(a,T,body'))
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   177
|   cont_eta_contract(f$t) = cont_eta_contract f $ cont_eta_contract t
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   178
|   cont_eta_contract t    = t;
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   179
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   180
fun idx_name dnames s n = s^(if length dnames = 1 then "" else string_of_int n);
1834
c780a4f39454 re-added when_funs to library.ML
oheimb
parents: 1828
diff changeset
   181
fun when_funs cons = if length cons = 1 then ["f"] 
c780a4f39454 re-added when_funs to library.ML
oheimb
parents: 1828
diff changeset
   182
                     else mapn (fn n => K("f"^(string_of_int n))) 1 cons;
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   183
fun when_body cons funarg = let
1637
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   184
	fun one_fun n (_,[]  ) = /\ "dummy" (funarg(1,n))
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   185
	|   one_fun n (_,args) = let
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   186
		val l2 = length args;
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   187
		fun idxs m arg = (if is_lazy arg then fn x=> %%"lift"`%%"ID"`x
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   188
					         else Id) (Bound(l2-m));
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   189
		in cont_eta_contract (foldr'' 
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   190
			(fn (a,t) => %%"ssplit"`(/\# (a,t)))
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   191
			(args,
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   192
			fn a=> /\#(a,(mk_cfapp(funarg(l2,n),mapn idxs 1 args))))
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   193
			) end;
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   194
in (if length cons = 1 andalso length(snd(hd cons)) <= 1
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   195
    then fn t => %%"strictify"`t else Id)
b8a8ae2e5de1 Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents: 1461
diff changeset
   196
     (foldr' (fn (x,y)=> %%"sswhen"`x`y) (mapn one_fun 1 cons)) end;
1274
ea0668a1c0ba added 8bit pragmas
regensbu
parents:
diff changeset
   197
end; (* struct *)