src/HOLCF/Tools/Domain/domain_library.ML
author huffman
Mon, 22 Mar 2010 15:05:20 -0700
changeset 35905 3d699b736ff4
parent 35562 e27550a842b9
child 35912 b0e300bd3a2c
permissions -rw-r--r--
fix ML warning in domain_library.ML
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32126
a5042f260440 obey captialized directory names convention
haftmann
parents: 31986
diff changeset
     1
(*  Title:      HOLCF/Tools/Domain/domain_library.ML
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     2
    Author:     David von Oheimb
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     3
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     4
Library for domain command.
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     5
*)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     6
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     7
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
     8
(* infix syntax *)
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
     9
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    10
infixr 5 -->;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    11
infixr 6 ->>;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    12
infixr 0 ===>;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    13
infixr 0 ==>;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    14
infix 0 ==;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    15
infix 1 ===;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    16
infix 1 ~=;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    17
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    18
infix 9 `  ;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    19
infix 9 `% ;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    20
infix 9 `%%;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    21
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    22
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    23
(* ----- specific support for domain ---------------------------------------- *)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    24
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    25
signature DOMAIN_LIBRARY =
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    26
sig
35465
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
    27
  val first  : 'a * 'b * 'c -> 'a
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
    28
  val second : 'a * 'b * 'c -> 'b
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
    29
  val third  : 'a * 'b * 'c -> 'c
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
    30
  val upd_second : ('b -> 'd) -> 'a * 'b * 'c -> 'a * 'd * 'c
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
    31
  val upd_third  : ('c -> 'd) -> 'a * 'b * 'c -> 'a * 'b * 'd
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
    32
  val mapn : (int -> 'a -> 'b) -> int -> 'a list -> 'b list
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
    33
  val atomize : Proof.context -> thm -> thm list
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
    34
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    35
  val Imposs : string -> 'a;
31162
6dc708ca4a8f add cpo_type function
huffman
parents: 31076
diff changeset
    36
  val cpo_type : theory -> typ -> bool;
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    37
  val pcpo_type : theory -> typ -> bool;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    38
  val string_of_typ : theory -> typ -> string;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    39
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    40
  (* Creating HOLCF types *)
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    41
  val mk_ssumT : typ * typ -> typ;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    42
  val mk_sprodT : typ * typ -> typ;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    43
  val mk_uT : typ -> typ;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    44
  val oneT : typ;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    45
  val pcpoS : sort;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    46
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    47
  (* Creating HOLCF terms *)
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    48
  val %: : string -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    49
  val %%: : string -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    50
  val ` : term * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    51
  val `% : term * string -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    52
  val UU : term;
31231
9434cd5ef24a export ID, oo; add more dtyp operations
huffman
parents: 31229
diff changeset
    53
  val ID : term;
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    54
  val list_ccomb : term * term list -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    55
  val con_app2 : string -> ('a -> term) -> 'a list -> term;
35497
979706bd5c16 re-enable bisim code, now in domain_theorems.ML
huffman
parents: 35465
diff changeset
    56
  val prj : ('a -> 'b -> 'a) -> ('a -> 'b -> 'a) -> 'a -> 'b list -> int -> 'a
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    57
  val proj : term -> 'a list -> int -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    58
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    59
  (* Creating propositions *)
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    60
  val mk_conj : term * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    61
  val mk_disj : term * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    62
  val mk_imp : term * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    63
  val mk_lam : string * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    64
  val mk_all : string * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    65
  val mk_ex : string * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    66
  val mk_constrainall : string * typ * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    67
  val === : term * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    68
  val defined : term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    69
  val mk_adm : term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    70
  val lift : ('a -> term) -> 'a list * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    71
  val lift_defined : ('a -> term) -> 'a list * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    72
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    73
  (* Creating meta-propositions *)
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    74
  val mk_trp : term -> term; (* HOLogic.mk_Trueprop *)
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    75
  val == : term * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    76
  val ===> : term * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    77
  val mk_All : string * term -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    78
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
    79
      (* Domain specifications *)
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
    80
      eqtype arg;
35521
47eec4da124a remove unused mixfix component from type cons
huffman
parents: 35519
diff changeset
    81
  type cons = string * arg list;
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    82
  type eq = (string * typ list) * cons list;
35519
abf45a91d24d remove unused selector field from type arg
huffman
parents: 35497
diff changeset
    83
  val mk_arg : (bool * Datatype.dtyp) * string -> arg;
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    84
  val is_lazy : arg -> bool;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    85
  val rec_of : arg -> int;
31738
7b9b9ba532ca discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents: 31288
diff changeset
    86
  val dtyp_of : arg -> Datatype.dtyp;
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    87
  val vname : arg -> string;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    88
  val upd_vname : (string -> string) -> arg -> arg;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    89
  val is_rec : arg -> bool;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    90
  val is_nonlazy_rec : arg -> bool;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    91
  val nonlazy : arg list -> string list;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    92
  val nonlazy_rec : arg list -> string list;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    93
  val %# : arg -> term;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    94
  val bound_arg : ''a list -> ''a -> term; (* ''a = arg or string *)
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    95
  val idx_name : 'a list -> string -> int -> string;
31228
bcacfd816d28 make type Domain_Library.arg abstract
huffman
parents: 31162
diff changeset
    96
  val con_app : string -> arg list -> term;
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    97
end;
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
    98
31023
d027411c9a38 use opaque ascription for all HOLCF code
huffman
parents: 31006
diff changeset
    99
structure Domain_Library :> DOMAIN_LIBRARY =
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
   100
struct
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   101
35465
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   102
fun first  (x,_,_) = x;
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   103
fun second (_,x,_) = x;
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   104
fun third  (_,_,x) = x;
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   105
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   106
fun upd_first  f (x,y,z) = (f x,   y,   z);
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   107
fun upd_second f (x,y,z) = (  x, f y,   z);
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   108
fun upd_third  f (x,y,z) = (  x,   y, f z);
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   109
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   110
fun mapn f n []      = []
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   111
  | mapn f n (x::xs) = (f n x) :: mapn f (n+1) xs;
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   112
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   113
fun foldr'' f (l,f2) =
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   114
    let fun itr []  = raise Fail "foldr''" 
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   115
          | itr [a] = f2 a
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   116
          | itr (a::l) = f(a, itr l)
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   117
    in  itr l  end;
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   118
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   119
fun atomize ctxt thm =
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   120
    let
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   121
      val r_inst = read_instantiate ctxt;
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   122
      fun at thm =
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   123
          case concl_of thm of
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   124
            _$(Const("op &",_)$_$_)       => at(thm RS conjunct1)@at(thm RS conjunct2)
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   125
          | _$(Const("All" ,_)$Abs(s,_,_))=> at(thm RS (r_inst [(("x", 0), "?" ^ s)] spec))
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   126
          | _                             => [thm];
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   127
    in map zero_var_indexes (at thm) end;
064bb6e9ace0 remove dead code
huffman
parents: 35443
diff changeset
   128
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   129
exception Impossible of string;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   130
fun Imposs msg = raise Impossible ("Domain:"^msg);
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   131
31162
6dc708ca4a8f add cpo_type function
huffman
parents: 31076
diff changeset
   132
fun cpo_type sg t = Sign.of_sort sg (Sign.certify_typ sg t, @{sort cpo});
30910
a7cc0ef93269 set up domain package in Domain.thy
huffman
parents: 30595
diff changeset
   133
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
   134
fun string_of_typ sg = Syntax.string_of_typ_global sg o Sign.certify_typ sg;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   135
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   136
(* ----- constructor list handling ----- *)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   137
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
   138
type arg =
31738
7b9b9ba532ca discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents: 31288
diff changeset
   139
     (bool * Datatype.dtyp) *   (*  (lazy, recursive element) *)
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   140
     string;                       (*   argument name    *)
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
   141
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
   142
type cons =
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   143
     string *         (* operator name of constr *)
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   144
     arg list;        (* argument list      *)
31006
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
   145
644d18da3c77 add module signature to domain_library.ML
huffman
parents: 30910
diff changeset
   146
type eq =
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   147
     (string *        (* name      of abstracted type *)
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   148
      typ list) *     (* arguments of abstracted type *)
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   149
     cons list;       (* represented type, as a constructor list *)
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   150
31228
bcacfd816d28 make type Domain_Library.arg abstract
huffman
parents: 31162
diff changeset
   151
val mk_arg = I;
31229
8a890890d143 change representation of Domain_Library.arg
huffman
parents: 31228
diff changeset
   152
35519
abf45a91d24d remove unused selector field from type arg
huffman
parents: 35497
diff changeset
   153
fun rec_of ((_,dtyp),_) =
33971
9c7fa7f76950 modernized structure Datatype_Aux
haftmann
parents: 33396
diff changeset
   154
    case dtyp of Datatype_Aux.DtRec i => i | _ => ~1;
31229
8a890890d143 change representation of Domain_Library.arg
huffman
parents: 31228
diff changeset
   155
(* FIXME: what about indirect recursion? *)
8a890890d143 change representation of Domain_Library.arg
huffman
parents: 31228
diff changeset
   156
35519
abf45a91d24d remove unused selector field from type arg
huffman
parents: 35497
diff changeset
   157
fun is_lazy arg = fst (fst arg);
abf45a91d24d remove unused selector field from type arg
huffman
parents: 35497
diff changeset
   158
fun dtyp_of arg = snd (fst arg);
abf45a91d24d remove unused selector field from type arg
huffman
parents: 35497
diff changeset
   159
val     vname =       snd;
abf45a91d24d remove unused selector field from type arg
huffman
parents: 35497
diff changeset
   160
val upd_vname =   apsnd;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   161
fun is_rec         arg = rec_of arg >=0;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   162
fun is_nonlazy_rec arg = is_rec arg andalso not (is_lazy arg);
33317
b4534348b8fd standardized filter/filter_out;
wenzelm
parents: 32126
diff changeset
   163
fun nonlazy     args   = map vname (filter_out is_lazy args);
b4534348b8fd standardized filter/filter_out;
wenzelm
parents: 32126
diff changeset
   164
fun nonlazy_rec args   = map vname (filter is_nonlazy_rec args);
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   165
31231
9434cd5ef24a export ID, oo; add more dtyp operations
huffman
parents: 31229
diff changeset
   166
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   167
(* ----- support for type and mixfix expressions ----- *)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   168
30910
a7cc0ef93269 set up domain package in Domain.thy
huffman
parents: 30595
diff changeset
   169
fun mk_uT T = Type(@{type_name "u"}, [T]);
35525
fa231b86cb1e proper names for types cfun, sprod, ssum
huffman
parents: 35522
diff changeset
   170
fun mk_sprodT (T, U) = Type(@{type_name sprod}, [T, U]);
fa231b86cb1e proper names for types cfun, sprod, ssum
huffman
parents: 35522
diff changeset
   171
fun mk_ssumT (T, U) = Type(@{type_name ssum}, [T, U]);
30910
a7cc0ef93269 set up domain package in Domain.thy
huffman
parents: 30595
diff changeset
   172
val oneT = @{typ one};
a7cc0ef93269 set up domain package in Domain.thy
huffman
parents: 30595
diff changeset
   173
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   174
(* ----- support for term expressions ----- *)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   175
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   176
fun %: s = Free(s,dummyT);
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   177
fun %# arg = %:(vname arg);
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   178
fun %%: s = Const(s,dummyT);
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   179
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   180
local open HOLogic in
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   181
val mk_trp = mk_Trueprop;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   182
fun mk_conj (S,T) = conj $ S $ T;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   183
fun mk_disj (S,T) = disj $ S $ T;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   184
fun mk_imp  (S,T) = imp  $ S $ T;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   185
fun mk_lam  (x,T) = Abs(x,dummyT,T);
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   186
fun mk_all  (x,P) = HOLogic.mk_all (x,dummyT,P);
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   187
fun mk_ex   (x,P) = mk_exists (x,dummyT,P);
24680
0d355aa59e67 TypeInfer.constrain: canonical argument order;
wenzelm
parents: 23284
diff changeset
   188
fun mk_constrainall (x,typ,P) = %%:"All" $ (TypeInfer.constrain (typ --> boolT) (mk_lam(x,P)));
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   189
end
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   190
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   191
fun mk_All  (x,P) = %%:"all" $ mk_lam(x,P); (* meta universal quantification *)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   192
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   193
infixr 0 ===>;  fun S ===> T = %%:"==>" $ S $ T;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   194
infix 0 ==;     fun S ==  T = %%:"==" $ S $ T;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   195
infix 1 ===;    fun S === T = %%:"op =" $ S $ T;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   196
infix 1 ~=;     fun S ~=  T = HOLogic.mk_not (S === T);
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   197
30595
c87a3350f5a9 proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents: 30190
diff changeset
   198
infix 9 `  ; fun f ` x = %%: @{const_name Rep_CFun} $ f $ x;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   199
infix 9 `% ; fun f`% s = f` %: s;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   200
infix 9 `%%; fun f`%%s = f` %%:s;
26012
f6917792f8a4 new term-building combinators
huffman
parents: 25723
diff changeset
   201
30595
c87a3350f5a9 proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents: 30190
diff changeset
   202
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
   203
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
   204
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
   205
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
   206
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
   207
fun mk_fup (t,u) = %%: @{const_name fup} ` t ` u;
26012
f6917792f8a4 new term-building combinators
huffman
parents: 25723
diff changeset
   208
f6917792f8a4 new term-building combinators
huffman
parents: 25723
diff changeset
   209
val pcpoS = @{sort pcpo};
f6917792f8a4 new term-building combinators
huffman
parents: 25723
diff changeset
   210
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   211
val list_ccomb = Library.foldl (op `); (* continuous version of list_comb *)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   212
fun con_app2 con f args = list_ccomb(%%:con,map f args);
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   213
fun con_app con = con_app2 con %#;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   214
fun prj _  _  x (   _::[]) _ = x
35905
3d699b736ff4 fix ML warning in domain_library.ML
huffman
parents: 35562
diff changeset
   215
  | prj _  _  _ []         _ = error "Domain_Library.prj: empty list"
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   216
  | prj f1 _  x (_::y::ys) 0 = f1 x y
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   217
  | prj f1 f2 x (y::   ys) j = prj f1 f2 (f2 x y) ys (j-1);
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   218
fun  proj x      = prj (fn S => K(%%:"fst" $S)) (fn S => K(%%:"snd" $S)) x;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   219
fun lift tfn = Library.foldr (fn (x,t)=> (mk_trp(tfn x) ===> t));
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   220
30595
c87a3350f5a9 proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents: 30190
diff changeset
   221
val UU = %%: @{const_name UU};
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   222
fun defined t = t ~= UU;
33396
45c5c3c51918 domain package no longer uses cfst/csnd/cpair
huffman
parents: 33317
diff changeset
   223
fun cpair (t,u) = %%: @{const_name Pair} $ t $ u;
30595
c87a3350f5a9 proper spacing before ML antiquotations -- note that @ may be part of symbolic ML identifiers;
wenzelm
parents: 30190
diff changeset
   224
fun spair (t,u) = %%: @{const_name spair}`t`u;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   225
fun lift_defined f = lift (fn x => defined (f x));
31986
a68f88d264f7 dropped find_index_eq
haftmann
parents: 31738
diff changeset
   226
fun bound_arg vns v = Bound (length vns - find_index (fn v' => v' = v) vns - 1);
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   227
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   228
fun cont_eta_contract (Const("Cfun.Abs_CFun",TT) $ Abs(a,T,body)) = 
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   229
    (case cont_eta_contract body  of
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   230
       body' as (Const("Cfun.Rep_CFun",Ta) $ f $ Bound 0) => 
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   231
       if not (0 mem loose_bnos f) then incr_boundvars ~1 f 
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   232
       else   Const("Cfun.Abs_CFun",TT) $ Abs(a,T,body')
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   233
     | body' => Const("Cfun.Abs_CFun",TT) $ Abs(a,T,body'))
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   234
  | cont_eta_contract(f$t) = cont_eta_contract f $ cont_eta_contract t
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   235
  | cont_eta_contract t    = t;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   236
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   237
fun idx_name dnames s n = s^(if length dnames = 1 then "" else string_of_int n);
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31231
diff changeset
   238
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   239
end; (* struct *)