author | wenzelm |
Mon, 09 Mar 1998 16:16:21 +0100 | |
changeset 4709 | d24168720303 |
parent 4122 | f63c283cefaf |
child 5291 | 5706f0ef1d43 |
permissions | -rw-r--r-- |
2453 | 1 |
(* Title: HOLCF/domain/syntax.ML |
2445
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
1637
diff
changeset
|
2 |
ID: $Id$ |
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
1637
diff
changeset
|
3 |
Author : David von Oheimb |
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
1637
diff
changeset
|
4 |
Copyright 1995, 1996 TU Muenchen |
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
1637
diff
changeset
|
5 |
|
51993fea433f
removed Holcfb.thy and Holcfb.ML, moving classical3 to HOL.ML as classical2
oheimb
parents:
1637
diff
changeset
|
6 |
syntax generator for domain section |
1274 | 7 |
*) |
8 |
||
9 |
structure Domain_Syntax = struct |
|
10 |
||
11 |
local |
|
12 |
||
13 |
open Domain_Library; |
|
4122 | 14 |
infixr 5 -->; infixr 6 ->>; |
15 |
fun calc_syntax dtypeprod ((dname, typevars), |
|
16 |
(cons': (string * mixfix * (bool*string*typ) list) list)) = |
|
1274 | 17 |
let |
4122 | 18 |
(* ----- constants concerning the isomorphism ------------------------------- *) |
1274 | 19 |
|
20 |
local |
|
4122 | 21 |
fun opt_lazy (lazy,_,t) = if lazy then mk_uT t else t |
22 |
fun prod (_,_,args) = if args = [] then oneT |
|
23 |
else foldr' mk_sprodT (map opt_lazy args); |
|
24 |
fun freetvar s = let val tvar = mk_TFree s in |
|
25 |
if tvar mem typevars then freetvar ("t"^s) else tvar end; |
|
26 |
fun when_type (_ ,_,args) = foldr (op ->>) (map third args,freetvar "t"); |
|
1274 | 27 |
in |
28 |
val dtype = Type(dname,typevars); |
|
4122 | 29 |
val dtype2 = foldr' mk_ssumT (map prod cons'); |
4008 | 30 |
val dnam = Sign.base_name dname; |
4122 | 31 |
val const_rep = (dnam^"_rep" , dtype ->> dtype2, NoSyn); |
32 |
val const_abs = (dnam^"_abs" , dtype2 ->> dtype , NoSyn); |
|
33 |
val const_when = (dnam^"_when",foldr (op ->>) ((map when_type cons'), |
|
34 |
dtype ->> freetvar "t"), NoSyn); |
|
35 |
val const_copy = (dnam^"_copy", dtypeprod ->> dtype ->> dtype , NoSyn); |
|
1274 | 36 |
end; |
37 |
||
4122 | 38 |
(* ----- constants concerning constructors, discriminators, and selectors --- *) |
1274 | 39 |
|
40 |
local |
|
41 |
val escape = let |
|
4122 | 42 |
fun esc (c::cs) = if c mem ["'","_","(",")","/"] then "'"::c::esc cs |
43 |
else c::esc cs |
|
44 |
| esc [] = [] |
|
4709 | 45 |
in implode o esc o Symbol.explode end; |
4122 | 46 |
fun con (name,s,args) = (name,foldr (op ->>) (map third args,dtype),s); |
47 |
fun dis (con ,s,_ ) = (dis_name_ con, dtype->>trT, |
|
48 |
Mixfix(escape ("is_" ^ con), [], max_pri)); |
|
49 |
(* stricly speaking, these constants have one argument, |
|
50 |
but the mixfix (without arguments) is introduced only |
|
51 |
to generate parse rules for non-alphanumeric names*) |
|
52 |
fun sel (_ ,_,args) = map (fn(_,sel,typ)=>(sel,dtype ->> typ,NoSyn))args; |
|
1274 | 53 |
in |
54 |
val consts_con = map con cons'; |
|
55 |
val consts_dis = map dis cons'; |
|
56 |
val consts_sel = flat(map sel cons'); |
|
57 |
end; |
|
58 |
||
4122 | 59 |
(* ----- constants concerning induction ------------------------------------- *) |
1274 | 60 |
|
4122 | 61 |
val const_take = (dnam^"_take" , HOLogic.natT-->dtype->>dtype, NoSyn); |
62 |
val const_finite = (dnam^"_finite", dtype-->HOLogic.boolT , NoSyn); |
|
1274 | 63 |
|
4122 | 64 |
(* ----- case translation --------------------------------------------------- *) |
1274 | 65 |
|
66 |
local open Syntax in |
|
67 |
val case_trans = let |
|
4122 | 68 |
fun c_ast con mx = Constant (const_name con mx); |
69 |
fun expvar n = Variable ("e"^(string_of_int n)); |
|
70 |
fun argvar n m _ = Variable ("a"^(string_of_int n)^"_"^ |
|
71 |
(string_of_int m)); |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
72 |
fun app s (l,r) = mk_appl (Constant s) [l,r]; |
4122 | 73 |
fun case1 n (con,mx,args) = mk_appl (Constant "@case1") |
74 |
[foldl (app "fapp") (c_ast con mx, (mapn (argvar n) 1 args)), |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
75 |
expvar n]; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
76 |
fun arg1 n (con,_,args) = if args = [] then expvar n |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
77 |
else mk_appl (Constant "LAM ") |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
78 |
[foldr' (app "_idts") (mapn (argvar n) 1 args) , expvar n]; |
3534 | 79 |
in |
80 |
ParsePrintRule |
|
81 |
(mk_appl (Constant "@case") [Variable "x", foldr' |
|
4122 | 82 |
(fn (c,cs) => mk_appl (Constant"@case2") [c,cs]) |
3534 | 83 |
(mapn case1 1 cons')], |
4122 | 84 |
mk_appl (Constant "fapp") [foldl |
85 |
(fn (w,a ) => mk_appl (Constant"fapp" ) [w,a ]) |
|
4008 | 86 |
(Constant (dnam^"_when"),mapn arg1 1 cons'), |
3534 | 87 |
Variable "x"]) |
1274 | 88 |
end; |
89 |
end; |
|
90 |
||
91 |
in ([const_rep, const_abs, const_when, const_copy] @ |
|
92 |
consts_con @ consts_dis @ consts_sel @ |
|
93 |
[const_take, const_finite], |
|
94 |
[case_trans]) |
|
95 |
end; (* let *) |
|
96 |
||
4122 | 97 |
(* ----- putting all the syntax stuff together ------------------------------ *) |
1274 | 98 |
|
99 |
in (* local *) |
|
100 |
||
4008 | 101 |
fun add_syntax (comp_dnam,eqs': ((string * typ list) * |
4122 | 102 |
(string * mixfix * (bool*string*typ) list) list) list) thy'' = |
1274 | 103 |
let |
4122 | 104 |
val dtypes = map (Type o fst) eqs'; |
105 |
val boolT = HOLogic.boolT; |
|
106 |
val funprod = foldr' mk_prodT (map (fn tp => tp ->> tp ) dtypes); |
|
107 |
val relprod = foldr' mk_prodT (map (fn tp => tp --> tp --> boolT) dtypes); |
|
108 |
val const_copy = (comp_dnam^"_copy" ,funprod ->> funprod, NoSyn); |
|
109 |
val const_bisim = (comp_dnam^"_bisim" ,relprod --> boolT , NoSyn); |
|
1274 | 110 |
val ctt = map (calc_syntax funprod) eqs'; |
4122 | 111 |
in thy'' |> ContConsts.add_consts_i (flat (map fst ctt) @ |
112 |
(if length eqs'>1 then [const_copy] else[])@ |
|
113 |
[const_bisim]) |
|
3771 | 114 |
|> Theory.add_trrules_i (flat(map snd ctt)) |
1274 | 115 |
end; (* let *) |
116 |
||
117 |
end; (* local *) |
|
118 |
end; (* struct *) |