src/HOLCF/Tools/Domain/domain_extender.ML
author huffman
Sun, 14 Mar 2010 19:48:33 -0700
changeset 35794 8cd7134275cc
parent 35776 b0bc15d8ad3b
child 35839 a601da1056b3
permissions -rw-r--r--
use headers consistently
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_extender.ML
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     2
    Author:     David von Oheimb
35794
8cd7134275cc use headers consistently
huffman
parents: 35776
diff changeset
     3
    Author:     Brian Huffman
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     4
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     5
Theory extender for domain command, including theory syntax.
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     6
*)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     7
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     8
signature DOMAIN_EXTENDER =
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
     9
sig
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    10
  val add_domain_cmd:
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
    11
      binding ->
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    12
      ((string * string option) list * binding * mixfix *
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    13
       (binding * (bool * binding option * string) list * mixfix) list) list
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    14
      -> theory -> theory
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    15
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    16
  val add_domain:
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
    17
      binding ->
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    18
      ((string * string option) list * binding * mixfix *
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    19
       (binding * (bool * binding option * typ) list * mixfix) list) list
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    20
      -> theory -> theory
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    21
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    22
  val add_new_domain_cmd:
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
    23
      binding ->
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    24
      ((string * string option) list * binding * mixfix *
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    25
       (binding * (bool * binding option * string) list * mixfix) list) list
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    26
      -> theory -> theory
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    27
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    28
  val add_new_domain:
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
    29
      binding ->
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    30
      ((string * string option) list * binding * mixfix *
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    31
       (binding * (bool * binding option * typ) list * mixfix) list) list
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    32
      -> theory -> theory
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    33
end;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    34
31023
d027411c9a38 use opaque ascription for all HOLCF code
huffman
parents: 30919
diff changeset
    35
structure Domain_Extender :> DOMAIN_EXTENDER =
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    36
struct
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    37
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    38
open Domain_Library;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    39
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    40
(* ----- general testing and preprocessing of constructor list -------------- *)
30919
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30916
diff changeset
    41
fun check_and_sort_domain
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    42
    (definitional : bool)
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    43
    (dtnvs : (string * typ list) list)
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    44
    (cons'' : (binding * (bool * binding option * typ) list * mixfix) list list)
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    45
    (thy : theory)
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31229
diff changeset
    46
    : ((string * typ list) *
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31229
diff changeset
    47
       (binding * (bool * binding option * typ) list * mixfix) list) list =
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    48
  let
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    49
    val defaultS = Sign.defaultS thy;
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    50
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    51
    val test_dupl_typs =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    52
      case duplicates (op =) (map fst dtnvs) of 
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    53
        [] => false | dups => error ("Duplicate types: " ^ commas_quote dups);
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    54
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    55
    val all_cons = map (Binding.name_of o first) (flat cons'');
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    56
    val test_dupl_cons =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    57
      case duplicates (op =) all_cons of 
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    58
        [] => false | dups => error ("Duplicate constructors: " 
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    59
                                      ^ commas_quote dups);
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    60
    val all_sels =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    61
      (map Binding.name_of o map_filter second o maps second) (flat cons'');
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    62
    val test_dupl_sels =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    63
      case duplicates (op =) all_sels of
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    64
        [] => false | dups => error("Duplicate selectors: "^commas_quote dups);
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    65
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    66
    fun test_dupl_tvars s =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    67
      case duplicates (op =) (map(fst o dest_TFree)s) of
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    68
        [] => false | dups => error("Duplicate type arguments: " 
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    69
                                    ^commas_quote dups);
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    70
    val test_dupl_tvars' = exists test_dupl_tvars (map snd dtnvs);
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    71
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    72
    (* test for free type variables, illegal sort constraints on rhs,
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    73
       non-pcpo-types and invalid use of recursive type;
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    74
       replace sorts in type variables on rhs *)
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    75
    fun analyse_equation ((dname,typevars),cons') = 
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    76
      let
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    77
        val tvars = map dest_TFree typevars;
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    78
        val distinct_typevars = map TFree tvars;
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    79
        fun rm_sorts (TFree(s,_)) = TFree(s,[])
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    80
          | rm_sorts (Type(s,ts)) = Type(s,remove_sorts ts)
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    81
          | rm_sorts (TVar(s,_))  = TVar(s,[])
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    82
        and remove_sorts l = map rm_sorts l;
35525
fa231b86cb1e proper names for types cfun, sprod, ssum
huffman
parents: 35521
diff changeset
    83
        val indirect_ok =
fa231b86cb1e proper names for types cfun, sprod, ssum
huffman
parents: 35521
diff changeset
    84
            [@{type_name "*"}, @{type_name cfun}, @{type_name ssum},
fa231b86cb1e proper names for types cfun, sprod, ssum
huffman
parents: 35521
diff changeset
    85
             @{type_name sprod}, @{type_name u}];
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    86
        fun analyse indirect (TFree(v,s))  =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    87
            (case AList.lookup (op =) tvars v of 
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    88
               NONE => error ("Free type variable " ^ quote v ^ " on rhs.")
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    89
             | SOME sort => if eq_set (op =) (s, defaultS) orelse
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    90
                               eq_set (op =) (s, sort)
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    91
                            then TFree(v,sort)
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    92
                            else error ("Inconsistent sort constraint" ^
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    93
                                        " for type variable " ^ quote v))
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    94
          | analyse indirect (t as Type(s,typl)) =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    95
            (case AList.lookup (op =) dtnvs s of
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    96
               NONE =>
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
    97
                 if definitional orelse s mem indirect_ok
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    98
                 then Type(s,map (analyse false) typl)
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
    99
                 else Type(s,map (analyse true) typl)
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   100
             | SOME typevars =>
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   101
                 if indirect 
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   102
                 then error ("Indirect recursion of type " ^ 
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   103
                             quote (string_of_typ thy t))
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   104
                 else if dname <> s orelse
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   105
                         (** BUG OR FEATURE?:
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   106
                             mutual recursion may use different arguments **)
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   107
                         remove_sorts typevars = remove_sorts typl 
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   108
                 then Type(s,map (analyse true) typl)
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   109
                 else error ("Direct recursion of type " ^ 
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   110
                             quote (string_of_typ thy t) ^ 
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   111
                             " with different arguments"))
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   112
          | analyse indirect (TVar _) = Imposs "extender:analyse";
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   113
        fun check_pcpo lazy T =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   114
            let val ok = if lazy then cpo_type else pcpo_type
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   115
            in if ok thy T then T
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   116
               else error ("Constructor argument type is not of sort pcpo: " ^
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   117
                           string_of_typ thy T)
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   118
            end;
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   119
        fun analyse_arg (lazy, sel, T) =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   120
            (lazy, sel, check_pcpo lazy (analyse false T));
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   121
        fun analyse_con (b, args, mx) = (b, map analyse_arg args, mx);
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   122
      in ((dname,distinct_typevars), map analyse_con cons') end; 
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   123
  in ListPair.map analyse_equation (dtnvs,cons'')
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   124
  end; (* let *)
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   125
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   126
(* ----- calls for building new thy and thms -------------------------------- *)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   127
30919
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30916
diff changeset
   128
fun gen_add_domain
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   129
    (prep_typ : theory -> 'a -> typ)
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   130
    (comp_dbind : binding)
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   131
    (eqs''' : ((string * string option) list * binding * mixfix *
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   132
               (binding * (bool * binding option * 'a) list * mixfix) list) list)
35516
59550ec4921d get rid of primes on thy variables
huffman
parents: 35498
diff changeset
   133
    (thy : theory) =
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   134
  let
35520
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   135
    val dtnvs : (binding * typ list * mixfix) list =
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   136
      let
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   137
        fun readS (SOME s) = Syntax.read_sort_global thy s
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   138
          | readS NONE = Sign.defaultS thy;
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   139
        fun readTFree (a, s) = TFree (a, readS s);
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   140
      in
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   141
        map (fn (vs,dname:binding,mx,_) =>
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   142
                (dname, map readTFree vs, mx)) eqs'''
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   143
      end;
31161
a27d4254ff4c fix domain package parsing of lhs sort constraints
huffman
parents: 31023
diff changeset
   144
35520
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   145
    (* declare new types *)
35516
59550ec4921d get rid of primes on thy variables
huffman
parents: 35498
diff changeset
   146
    val thy =
35520
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   147
      let
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   148
        fun thy_type  (dname,tvars,mx) = (dname, length tvars, mx);
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   149
        fun thy_arity (dname,tvars,mx) =
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   150
            (Sign.full_name thy dname, map (snd o dest_TFree) tvars, pcpoS);
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   151
      in
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   152
        thy
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   153
          |> Sign.add_types (map thy_type dtnvs)
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   154
          |> fold (AxClass.axiomatize_arity o thy_arity) dtnvs
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   155
      end;
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   156
35529
089e438b925b simplify add_axioms function; remove obsolete domain_syntax.ML
huffman
parents: 35525
diff changeset
   157
    val dbinds : binding list =
089e438b925b simplify add_axioms function; remove obsolete domain_syntax.ML
huffman
parents: 35525
diff changeset
   158
        map (fn (_,dbind,_,_) => dbind) eqs''';
35520
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   159
    val cons''' :
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   160
        (binding * (bool * binding option * 'a) list * mixfix) list list =
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   161
        map (fn (_,_,_,cons) => cons) eqs''';
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   162
    val cons'' :
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   163
        (binding * (bool * binding option * typ) list * mixfix) list list =
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   164
        map (map (upd_second (map (upd_third (prep_typ thy))))) cons''';
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   165
    val dtnvs' : (string * typ list) list =
35516
59550ec4921d get rid of primes on thy variables
huffman
parents: 35498
diff changeset
   166
      map (fn (dname,vs,mx) => (Sign.full_name thy dname,vs)) dtnvs;
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   167
    val eqs' : ((string * typ list) *
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   168
        (binding * (bool * binding option * typ) list * mixfix) list) list =
35520
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   169
        check_and_sort_domain false dtnvs' cons'' thy;
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   170
    val dts : typ list = map (Type o fst) eqs';
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   171
    val new_dts : (string * string list) list =
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   172
        map (fn ((s,Ts),_) => (s, map (fst o dest_TFree) Ts)) eqs';
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   173
    fun one_con (con,args,mx) : cons =
35129
ed24ba6f69aa discontinued unnamed infix syntax;
wenzelm
parents: 34149
diff changeset
   174
        (Binding.name_of con,  (* FIXME preverse binding (!?) *)
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   175
         ListPair.map (fn ((lazy,sel,tp),vn) =>
35519
abf45a91d24d remove unused selector field from type arg
huffman
parents: 35518
diff changeset
   176
           mk_arg ((lazy, Datatype_Aux.dtyp_of_typ new_dts tp), vn))
35520
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   177
                      (args, Datatype_Prop.make_tnames (map third args)));
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   178
    val eqs : eq list =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   179
        map (fn (dtnvs,cons') => (dtnvs, map one_con cons')) eqs';
35529
089e438b925b simplify add_axioms function; remove obsolete domain_syntax.ML
huffman
parents: 35525
diff changeset
   180
089e438b925b simplify add_axioms function; remove obsolete domain_syntax.ML
huffman
parents: 35525
diff changeset
   181
    fun mk_arg_typ (lazy, dest_opt, T) = if lazy then mk_uT T else T;
089e438b925b simplify add_axioms function; remove obsolete domain_syntax.ML
huffman
parents: 35525
diff changeset
   182
    fun mk_con_typ (bind, args, mx) =
089e438b925b simplify add_axioms function; remove obsolete domain_syntax.ML
huffman
parents: 35525
diff changeset
   183
        if null args then oneT else foldr1 mk_sprodT (map mk_arg_typ args);
089e438b925b simplify add_axioms function; remove obsolete domain_syntax.ML
huffman
parents: 35525
diff changeset
   184
    fun mk_eq_typ (_, cons) = foldr1 mk_ssumT (map mk_con_typ cons);
089e438b925b simplify add_axioms function; remove obsolete domain_syntax.ML
huffman
parents: 35525
diff changeset
   185
    val repTs : typ list = map mk_eq_typ eqs';
089e438b925b simplify add_axioms function; remove obsolete domain_syntax.ML
huffman
parents: 35525
diff changeset
   186
    val dom_eqns : (binding * (typ * typ)) list = dbinds ~~ (dts ~~ repTs);
35659
a78bc1930a7a include take_info within take_induct_info type
huffman
parents: 35658
diff changeset
   187
    val ((iso_infos, take_info), thy) =
35558
bb088a6fafbc add_axioms returns an iso_info; add_theorems takes an iso_info as an argument
huffman
parents: 35529
diff changeset
   188
        Domain_Axioms.add_axioms dom_eqns thy;
35529
089e438b925b simplify add_axioms function; remove obsolete domain_syntax.ML
huffman
parents: 35525
diff changeset
   189
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   190
    val ((rewss, take_rews), theorems_thy) =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   191
        thy
35776
b0bc15d8ad3b pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents: 35775
diff changeset
   192
          |> fold_map (fn (((dbind, eq), (_,cs)), info) =>
b0bc15d8ad3b pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents: 35775
diff changeset
   193
                Domain_Theorems.theorems (eq, eqs) dbind cs info take_info)
b0bc15d8ad3b pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents: 35775
diff changeset
   194
             (dbinds ~~ eqs ~~ eqs' ~~ iso_infos)
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   195
          ||>> Domain_Theorems.comp_theorems (comp_dbind, eqs) take_info;
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   196
  in
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   197
    theorems_thy
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   198
      |> PureThy.add_thmss
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   199
           [((Binding.qualified true "rews" comp_dbind,
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   200
              flat rewss @ take_rews), [])]
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   201
      |> snd
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   202
  end;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   203
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   204
fun gen_add_new_domain
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   205
    (prep_typ : theory -> 'a -> typ)
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   206
    (comp_dbind : binding)
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   207
    (eqs''' : ((string * string option) list * binding * mixfix *
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   208
               (binding * (bool * binding option * 'a) list * mixfix) list) list)
35516
59550ec4921d get rid of primes on thy variables
huffman
parents: 35498
diff changeset
   209
    (thy : theory) =
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   210
  let
35520
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   211
    val dtnvs : (binding * typ list * mixfix) list =
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   212
      let
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   213
        fun readS (SOME s) = Syntax.read_sort_global thy s
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   214
          | readS NONE = Sign.defaultS thy;
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   215
        fun readTFree (a, s) = TFree (a, readS s);
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   216
      in
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   217
        map (fn (vs,dname:binding,mx,_) =>
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   218
                (dname, map readTFree vs, mx)) eqs'''
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   219
      end;
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   220
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   221
    fun thy_type  (dname,tvars,mx) = (dname, length tvars, mx);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   222
    fun thy_arity (dname,tvars,mx) =
35516
59550ec4921d get rid of primes on thy variables
huffman
parents: 35498
diff changeset
   223
      (Sign.full_name thy dname, map (snd o dest_TFree) tvars, @{sort rep});
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   224
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   225
    (* this theory is used just for parsing and error checking *)
35516
59550ec4921d get rid of primes on thy variables
huffman
parents: 35498
diff changeset
   226
    val tmp_thy = thy
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   227
      |> Theory.copy
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   228
      |> Sign.add_types (map thy_type dtnvs)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   229
      |> fold (AxClass.axiomatize_arity o thy_arity) dtnvs;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   230
35776
b0bc15d8ad3b pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents: 35775
diff changeset
   231
    val dbinds : binding list =
b0bc15d8ad3b pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents: 35775
diff changeset
   232
        map (fn (_,dbind,_,_) => dbind) eqs''';
35520
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   233
    val cons''' :
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   234
        (binding * (bool * binding option * 'a) list * mixfix) list list =
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   235
        map (fn (_,_,_,cons) => cons) eqs''';
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   236
    val cons'' :
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   237
        (binding * (bool * binding option * typ) list * mixfix) list list =
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   238
        map (map (upd_second (map (upd_third (prep_typ tmp_thy))))) cons''';
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   239
    val dtnvs' : (string * typ list) list =
35520
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   240
        map (fn (dname,vs,mx) => (Sign.full_name thy dname,vs)) dtnvs;
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   241
    val eqs' : ((string * typ list) *
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   242
        (binding * (bool * binding option * typ) list * mixfix) list) list =
35520
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   243
        check_and_sort_domain true dtnvs' cons'' tmp_thy;
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   244
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   245
    fun mk_arg_typ (lazy, dest_opt, T) = if lazy then mk_uT T else T;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   246
    fun mk_con_typ (bind, args, mx) =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   247
        if null args then oneT else foldr1 mk_sprodT (map mk_arg_typ args);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   248
    fun mk_eq_typ (_, cons) = foldr1 mk_ssumT (map mk_con_typ cons);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   249
    
35659
a78bc1930a7a include take_info within take_induct_info type
huffman
parents: 35658
diff changeset
   250
    val ((iso_infos, take_info), thy) = thy |>
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   251
      Domain_Isomorphism.domain_isomorphism
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   252
        (map (fn ((vs, dname, mx, _), eq) =>
34149
a0efb4754cb7 add 'morphisms' option to domain_isomorphism command
huffman
parents: 33971
diff changeset
   253
                 (map fst vs, dname, mx, mk_eq_typ eq, NONE))
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   254
             (eqs''' ~~ eqs'))
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   255
35520
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   256
    val dts : typ list = map (Type o fst) eqs';
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   257
    val new_dts : (string * string list) list =
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   258
        map (fn ((s,Ts),_) => (s, map (fst o dest_TFree) Ts)) eqs';
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   259
    fun one_con (con,args,mx) : cons =
35129
ed24ba6f69aa discontinued unnamed infix syntax;
wenzelm
parents: 34149
diff changeset
   260
        (Binding.name_of con,   (* FIXME preverse binding (!?) *)
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   261
         ListPair.map (fn ((lazy,sel,tp),vn) =>
35519
abf45a91d24d remove unused selector field from type arg
huffman
parents: 35518
diff changeset
   262
           mk_arg ((lazy, Datatype_Aux.dtyp_of_typ new_dts tp), vn))
35443
2e0f9516947e change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents: 35288
diff changeset
   263
                      (args, Datatype_Prop.make_tnames (map third args))
35520
f433f18d4c41 cleaned up, added type annotations
huffman
parents: 35519
diff changeset
   264
        );
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   265
    val eqs : eq list =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   266
        map (fn (dtnvs,cons') => (dtnvs, map one_con cons')) eqs';
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   267
    val ((rewss, take_rews), theorems_thy) =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   268
        thy
35776
b0bc15d8ad3b pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents: 35775
diff changeset
   269
          |> fold_map (fn (((dbind, eq), (x,cs)), info) =>
b0bc15d8ad3b pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents: 35775
diff changeset
   270
               Domain_Theorems.theorems (eq, eqs) dbind cs info take_info)
b0bc15d8ad3b pass domain binding as argument to Domain_Theorems.theorems; proper qualified bindings for theorem names
huffman
parents: 35775
diff changeset
   271
             (dbinds ~~ eqs ~~ eqs' ~~ iso_infos)
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   272
          ||>> Domain_Theorems.comp_theorems (comp_dbind, eqs) take_info;
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   273
  in
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   274
    theorems_thy
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   275
      |> PureThy.add_thmss
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   276
           [((Binding.qualified true "rews" comp_dbind,
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   277
              flat rewss @ take_rews), [])]
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   278
      |> snd
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   279
  end;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   280
30919
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30916
diff changeset
   281
val add_domain = gen_add_domain Sign.certify_typ;
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30916
diff changeset
   282
val add_domain_cmd = gen_add_domain Syntax.read_typ_global;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   283
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   284
val add_new_domain = gen_add_new_domain Sign.certify_typ;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   285
val add_new_domain_cmd = gen_add_new_domain Syntax.read_typ_global;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   286
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   287
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   288
(** outer syntax **)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   289
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   290
local structure P = OuterParse and K = OuterKeyword in
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   291
27353
71c4dd53d4cb moved global keywords from OuterSyntax to OuterKeyword, tuned interfaces;
wenzelm
parents: 24926
diff changeset
   292
val _ = OuterKeyword.keyword "lazy";
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   293
30919
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30916
diff changeset
   294
val dest_decl : (bool * binding option * string) parser =
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   295
  P.$$$ "(" |-- Scan.optional (P.$$$ "lazy" >> K true) false --
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   296
    (P.binding >> SOME) -- (P.$$$ "::" |-- P.typ)  --| P.$$$ ")" >> P.triple1
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   297
    || P.$$$ "(" |-- P.$$$ "lazy" |-- P.typ --| P.$$$ ")"
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   298
    >> (fn t => (true,NONE,t))
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   299
    || P.typ >> (fn t => (false,NONE,t));
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   300
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   301
val cons_decl =
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   302
  P.binding -- Scan.repeat dest_decl -- P.opt_mixfix;
30916
a3d2128cac92 allow infix declarations for type constructors defined with domain package
huffman
parents: 30915
diff changeset
   303
31161
a27d4254ff4c fix domain package parsing of lhs sort constraints
huffman
parents: 31023
diff changeset
   304
val type_var' : (string * string option) parser =
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   305
  (P.type_ident -- Scan.option (P.$$$ "::" |-- P.!!! P.sort));
30916
a3d2128cac92 allow infix declarations for type constructors defined with domain package
huffman
parents: 30915
diff changeset
   306
31161
a27d4254ff4c fix domain package parsing of lhs sort constraints
huffman
parents: 31023
diff changeset
   307
val type_args' : (string * string option) list parser =
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   308
  type_var' >> single
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   309
  || P.$$$ "(" |-- P.!!! (P.list1 type_var' --| P.$$$ ")")
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   310
  || Scan.succeed [];
30916
a3d2128cac92 allow infix declarations for type constructors defined with domain package
huffman
parents: 30915
diff changeset
   311
a3d2128cac92 allow infix declarations for type constructors defined with domain package
huffman
parents: 30915
diff changeset
   312
val domain_decl =
35351
7425aece4ee3 allow general mixfix syntax for type constructors;
wenzelm
parents: 35288
diff changeset
   313
  (type_args' -- P.binding -- P.opt_mixfix) --
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   314
    (P.$$$ "=" |-- P.enum1 "|" cons_decl);
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   315
30916
a3d2128cac92 allow infix declarations for type constructors defined with domain package
huffman
parents: 30915
diff changeset
   316
val domains_decl =
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   317
  Scan.option (P.$$$ "(" |-- P.binding --| P.$$$ ")") --
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   318
    P.and_list1 domain_decl;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   319
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   320
fun mk_domain
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   321
    (definitional : bool)
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   322
    (opt_name : binding option,
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   323
     doms : ((((string * string option) list * binding) * mixfix) *
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   324
             ((binding * (bool * binding option * string) list) * mixfix) list) list ) =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   325
  let
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   326
    val names = map (fn (((_, t), _), _) => Binding.name_of t) doms;
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   327
    val specs : ((string * string option) list * binding * mixfix *
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   328
                 (binding * (bool * binding option * string) list * mixfix) list) list =
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   329
        map (fn (((vs, t), mx), cons) =>
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   330
                (vs, t, mx, map (fn ((c, ds), mx) => (c, ds, mx)) cons)) doms;
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   331
    val comp_dbind =
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   332
        case opt_name of NONE => Binding.name (space_implode "_" names)
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   333
                       | SOME s => s;
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   334
  in
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   335
    if definitional 
35774
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   336
    then add_new_domain_cmd comp_dbind specs
218e9766a848 replace some string arguments with bindings
huffman
parents: 35659
diff changeset
   337
    else add_domain_cmd comp_dbind specs
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   338
  end;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   339
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   340
val _ =
33796
6442aa3773a2 clean up indentation
huffman
parents: 33038
diff changeset
   341
  OuterSyntax.command "domain" "define recursive domains (HOLCF)"
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   342
    K.thy_decl (domains_decl >> (Toplevel.theory o mk_domain false));
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   343
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   344
val _ =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   345
  OuterSyntax.command "new_domain" "define recursive domains (HOLCF)"
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33796
diff changeset
   346
    K.thy_decl (domains_decl >> (Toplevel.theory o mk_domain true));
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   347
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   348
end;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   349
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   350
end;