src/HOLCF/Tools/Domain/domain_syntax.ML
author wenzelm
Mon, 01 Mar 2010 17:12:43 +0100
changeset 35414 cc8e4276d093
parent 35262 9ea4445d2ccf
child 35444 73f645fdd4ff
permissions -rw-r--r--
updated generated files;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32126
a5042f260440 obey captialized directory names convention
haftmann
parents: 31288
diff changeset
     1
(*  Title:      HOLCF/Tools/Domain/domain_syntax.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
Syntax generator 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
30919
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30912
diff changeset
     7
signature DOMAIN_SYNTAX =
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30912
diff changeset
     8
sig
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31226
diff changeset
     9
  val calc_syntax:
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
    10
      theory ->
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    11
      bool ->
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31226
diff changeset
    12
      typ ->
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31226
diff changeset
    13
      (string * typ list) *
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31226
diff changeset
    14
      (binding * (bool * binding option * typ) list * mixfix) list ->
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31226
diff changeset
    15
      (binding * typ * mixfix) list * ast Syntax.trrule list
31226
1dffa9a056b5 indentation; export Domain_Syntax.calc_syntax
huffman
parents: 31023
diff changeset
    16
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31226
diff changeset
    17
  val add_syntax:
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    18
      bool ->
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31226
diff changeset
    19
      string ->
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31226
diff changeset
    20
      ((string * typ list) *
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31226
diff changeset
    21
       (binding * (bool * binding option * typ) list * mixfix) list) list ->
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31226
diff changeset
    22
      theory -> theory
30919
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30912
diff changeset
    23
end;
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30912
diff changeset
    24
dcf8a7a66bd1 make domain package ML interface more consistent with datatype package; use binding instead of bstring
huffman
parents: 30912
diff changeset
    25
31023
d027411c9a38 use opaque ascription for all HOLCF code
huffman
parents: 30919
diff changeset
    26
structure Domain_Syntax :> DOMAIN_SYNTAX =
31226
1dffa9a056b5 indentation; export Domain_Syntax.calc_syntax
huffman
parents: 31023
diff changeset
    27
struct
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    28
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    29
open Domain_Library;
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    30
infixr 5 -->; infixr 6 ->>;
31226
1dffa9a056b5 indentation; export Domain_Syntax.calc_syntax
huffman
parents: 31023
diff changeset
    31
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
    32
fun calc_syntax thy
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    33
    (definitional : bool)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    34
    (dtypeprod : typ)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    35
    ((dname : string, typevars : typ list), 
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    36
     (cons': (binding * (bool * binding option * typ) list * mixfix) list))
31226
1dffa9a056b5 indentation; export Domain_Syntax.calc_syntax
huffman
parents: 31023
diff changeset
    37
    : (binding * typ * mixfix) list * ast Syntax.trrule list =
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    38
  let
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    39
(* ----- constants concerning the isomorphism ------------------------------- *)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    40
    local
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    41
      fun opt_lazy (lazy,_,t) = if lazy then mk_uT t else t
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    42
      fun prod     (_,args,_) = case args of [] => oneT
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    43
                                           | _ => foldr1 mk_sprodT (map opt_lazy args);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    44
      fun freetvar s = let val tvar = mk_TFree s in
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    45
                         if tvar mem typevars then freetvar ("t"^s) else tvar end;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    46
      fun when_type (_,args,_) = List.foldr (op ->>) (freetvar "t") (map third args);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    47
    in
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    48
    val dtype  = Type(dname,typevars);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    49
    val dtype2 = foldr1 mk_ssumT (map prod cons');
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    50
    val dnam = Long_Name.base_name dname;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    51
    fun dbind s = Binding.name (dnam ^ s);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    52
    val const_rep  = (dbind "_rep" ,              dtype  ->> dtype2, NoSyn);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    53
    val const_abs  = (dbind "_abs" ,              dtype2 ->> dtype , NoSyn);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    54
    val const_when = (dbind "_when", List.foldr (op ->>) (dtype ->> freetvar "t") (map when_type cons'), NoSyn);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    55
    val const_copy = (dbind "_copy", dtypeprod ->> dtype  ->> dtype , NoSyn);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    56
    end;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    57
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    58
(* ----- constants concerning constructors, discriminators, and selectors --- *)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    59
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    60
    local
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    61
      val escape = let
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    62
        fun esc (c::cs) = if c mem ["'","_","(",")","/"] then "'"::c::esc cs
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    63
                          else      c::esc cs
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
    64
          | esc []      = []
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    65
      in implode o esc o Symbol.explode end;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    66
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    67
      fun dis_name_ con =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    68
          Binding.name ("is_" ^ strip_esc (Binding.name_of con));
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    69
      fun mat_name_ con =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    70
          Binding.name ("match_" ^ strip_esc (Binding.name_of con));
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    71
      fun pat_name_ con =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    72
          Binding.name (strip_esc (Binding.name_of con) ^ "_pat");
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    73
      fun con (name,args,mx) =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    74
          (name, List.foldr (op ->>) dtype (map third args), mx);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    75
      fun dis (con,args,mx) =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    76
          (dis_name_ con, dtype->>trT,
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    77
           Mixfix(escape ("is_" ^ Binding.name_of con), [], Syntax.max_pri));
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    78
      (* strictly speaking, these constants have one argument,
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    79
       but the mixfix (without arguments) is introduced only
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    80
           to generate parse rules for non-alphanumeric names*)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    81
      fun freetvar s n =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    82
          let val tvar = mk_TFree (s ^ string_of_int n)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    83
          in if tvar mem typevars then freetvar ("t"^s) n else tvar end;
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
    84
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    85
      fun mk_matT (a,bs,c) =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    86
          a ->> List.foldr (op ->>) (mk_maybeT c) bs ->> mk_maybeT c;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    87
      fun mat (con,args,mx) =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    88
          (mat_name_ con,
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    89
           mk_matT(dtype, map third args, freetvar "t" 1),
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    90
           Mixfix(escape ("match_" ^ Binding.name_of con), [], Syntax.max_pri));
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    91
      fun sel1 (_,sel,typ) =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    92
          Option.map (fn s => (s,dtype ->> typ,NoSyn)) sel;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    93
      fun sel (con,args,mx) = map_filter sel1 args;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    94
      fun mk_patT (a,b)     = a ->> mk_maybeT b;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    95
      fun pat_arg_typ n arg = mk_patT (third arg, freetvar "t" n);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    96
      fun pat (con,args,mx) =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    97
          (pat_name_ con,
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    98
           (mapn pat_arg_typ 1 args)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
    99
             --->
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   100
             mk_patT (dtype, mk_ctupleT (map (freetvar "t") (1 upto length args))),
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   101
           Mixfix(escape (Binding.name_of con ^ "_pat"), [], Syntax.max_pri));
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   102
    in
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   103
    val consts_con = map con cons';
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   104
    val consts_dis = map dis cons';
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   105
    val consts_mat = map mat cons';
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   106
    val consts_pat = map pat cons';
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   107
    val consts_sel = maps sel cons';
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   108
    end;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   109
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   110
(* ----- constants concerning induction ------------------------------------- *)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   111
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   112
    val const_take   = (dbind "_take"  , HOLogic.natT-->dtype->>dtype, NoSyn);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   113
    val const_finite = (dbind "_finite", dtype-->HOLogic.boolT       , NoSyn);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   114
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   115
(* ----- case translation --------------------------------------------------- *)
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   116
35262
9ea4445d2ccf slightly more abstract syntax mark/unmark operations;
wenzelm
parents: 35258
diff changeset
   117
    fun syntax b = Syntax.mark_const (Sign.full_bname thy b);
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   118
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   119
    local open Syntax in
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   120
    local
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   121
      fun c_ast authentic con = Constant ((authentic ? syntax) (Binding.name_of con));
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   122
      fun expvar n = Variable ("e" ^ string_of_int n);
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   123
      fun argvar n m _ = Variable ("a" ^ string_of_int n ^ "_" ^ string_of_int m);
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   124
      fun argvars n args = mapn (argvar n) 1 args;
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   125
      fun app s (l, r) = mk_appl (Constant s) [l, r];
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   126
      val cabs = app "_cabs";
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   127
      val capp = app @{const_syntax Rep_CFun};
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   128
      fun con1 authentic n (con,args,mx) =
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   129
        Library.foldl capp (c_ast authentic con, argvars n args);
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   130
      fun case1 authentic n (con,args,mx) =
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   131
        app "_case1" (con1 authentic n (con,args,mx), expvar n);
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   132
      fun arg1 n (con,args,_) = List.foldr cabs (expvar n) (argvars n args);
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   133
      fun when1 n m = if n = m then arg1 n else K (Constant @{const_syntax UU});
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   134
          
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   135
      fun app_var x = mk_appl (Constant "_variable") [x, Variable "rhs"];
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   136
      fun app_pat x = mk_appl (Constant "_pat") [x];
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   137
      fun args_list [] = Constant "_noargs"
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   138
        | args_list xs = foldr1 (app "_args") xs;
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   139
    in
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   140
    fun case_trans authentic =
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   141
        ParsePrintRule
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   142
          (app "_case_syntax" (Variable "x", foldr1 (app "_case2") (mapn (case1 authentic) 1 cons')),
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   143
           capp (Library.foldl capp
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   144
            (Constant (syntax (dnam ^ "_when")), mapn arg1 1 cons'), Variable "x"));
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   145
        
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   146
    fun one_abscon_trans authentic n (con,mx,args) =
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   147
        ParsePrintRule
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   148
          (cabs (con1 authentic n (con,mx,args), expvar n),
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   149
           Library.foldl capp (Constant (syntax (dnam ^ "_when")), mapn (when1 n) 1 cons'));
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   150
    fun abscon_trans authentic = mapn (one_abscon_trans authentic) 1 cons';
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   151
        
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   152
    fun one_case_trans authentic (con,args,mx) =
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   153
      let
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   154
        val cname = c_ast authentic con;
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   155
        val pname = Constant (syntax (strip_esc (Binding.name_of con) ^ "_pat"));
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   156
        val ns = 1 upto length args;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   157
        val xs = map (fn n => Variable ("x"^(string_of_int n))) ns;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   158
        val ps = map (fn n => Variable ("p"^(string_of_int n))) ns;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   159
        val vs = map (fn n => Variable ("v"^(string_of_int n))) ns;
31288
67dff9c5b2bd remove hard tabs, fix indentation
huffman
parents: 31226
diff changeset
   160
      in
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   161
        [ParseRule (app_pat (Library.foldl capp (cname, xs)),
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   162
                    mk_appl pname (map app_pat xs)),
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   163
         ParseRule (app_var (Library.foldl capp (cname, xs)),
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   164
                    app_var (args_list xs)),
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   165
         PrintRule (Library.foldl capp (cname, ListPair.map (app "_match") (ps,vs)),
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   166
                    app "_match" (mk_appl pname ps, args_list vs))]
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   167
        end;
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   168
    val Case_trans = maps (one_case_trans false) cons' @ maps (one_case_trans true) cons';
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   169
    end;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   170
    end;
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33798
diff changeset
   171
    val optional_consts =
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33798
diff changeset
   172
        if definitional then [] else [const_rep, const_abs, const_copy];
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   173
33802
48ce3a1063f2 domain_isomorphism package defines copy functions
huffman
parents: 33798
diff changeset
   174
  in (optional_consts @ [const_when] @ 
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   175
      consts_con @ consts_dis @ consts_mat @ consts_pat @ consts_sel @
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   176
      [const_take, const_finite],
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   177
      (case_trans false :: case_trans true :: (abscon_trans false @ abscon_trans true @ Case_trans)))
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   178
  end; (* let *)
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   179
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   180
(* ----- putting all the syntax stuff together ------------------------------ *)
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   181
31226
1dffa9a056b5 indentation; export Domain_Syntax.calc_syntax
huffman
parents: 31023
diff changeset
   182
fun add_syntax
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   183
    (definitional : bool)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   184
    (comp_dnam : string)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   185
    (eqs' : ((string * typ list) *
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   186
             (binding * (bool * binding option * typ) list * mixfix) list) list)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   187
    (thy'' : theory) =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   188
  let
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   189
    val dtypes  = map (Type o fst) eqs';
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   190
    val boolT   = HOLogic.boolT;
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   191
    val funprod =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   192
        foldr1 HOLogic.mk_prodT (map (fn tp => tp ->> tp          ) dtypes);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   193
    val relprod =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   194
        foldr1 HOLogic.mk_prodT (map (fn tp => tp --> tp --> boolT) dtypes);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   195
    val const_copy =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   196
        (Binding.name (comp_dnam^"_copy"), funprod ->> funprod, NoSyn);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   197
    val const_bisim =
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   198
        (Binding.name (comp_dnam^"_bisim"), relprod --> boolT, NoSyn);
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   199
    val ctt : ((binding * typ * mixfix) list * ast Syntax.trrule list) list =
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   200
        map (calc_syntax thy'' definitional funprod) eqs';
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   201
  in thy''
35258
8154c5211ddb adapted to authentic syntax;
wenzelm
parents: 35129
diff changeset
   202
       |> Cont_Consts.add_consts
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   203
           (maps fst ctt @ 
33807
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   204
            (if length eqs'>1 andalso not definitional
ce8d2e8bca21 domain_isomorphism package defines combined copy function
huffman
parents: 33802
diff changeset
   205
             then [const_copy] else []) @
33798
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   206
            [const_bisim])
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   207
       |> Sign.add_trrules_i (maps snd ctt)
46cbbcbd4e68 clean up indentation; add 'definitional' option flag
huffman
parents: 33004
diff changeset
   208
  end; (* let *)
23152
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   209
9497234a2743 moved HOLCF tools to canonical place;
wenzelm
parents:
diff changeset
   210
end; (* struct *)