9 signature DEFS = |
9 signature DEFS = |
10 sig |
10 sig |
11 val pretty_const: Pretty.pp -> string * typ list -> Pretty.T |
11 val pretty_const: Pretty.pp -> string * typ list -> Pretty.T |
12 val plain_args: typ list -> bool |
12 val plain_args: typ list -> bool |
13 type T |
13 type T |
14 val specifications_of: T -> string -> (serial * {is_def: bool, thyname: string, name: string, |
14 val specifications_of: T -> string -> {is_def: bool, name: string, |
15 lhs: typ list, rhs: (string * typ list) list}) list |
15 lhs: typ list, rhs: (string * typ list) list} list |
|
16 val all_specifications_of: T -> (string * {is_def: bool, name: string, |
|
17 lhs: typ list, rhs: (string * typ list) list} list) list |
16 val dest: T -> |
18 val dest: T -> |
17 {restricts: ((string * typ list) * string) list, |
19 {restricts: ((string * typ list) * string) list, |
18 reducts: ((string * typ list) * (string * typ list) list) list} |
20 reducts: ((string * typ list) * (string * typ list) list) list} |
19 val empty: T |
21 val empty: T |
20 val merge: Pretty.pp -> T * T -> T |
22 val merge: Pretty.pp -> T * T -> T |
21 val define: Pretty.pp -> bool -> bool -> string -> string -> |
23 val define: Pretty.pp -> bool -> bool -> string -> |
22 string * typ list -> (string * typ list) list -> T -> T |
24 string * typ list -> (string * typ list) list -> T -> T |
23 end |
25 end |
24 |
26 |
25 structure Defs: DEFS = |
27 structure Defs: DEFS = |
26 struct |
28 struct |
49 (SOME (Type.raw_matches (Ts, Us) Vartab.empty) handle Type.TYPE_MATCH => NONE); |
51 (SOME (Type.raw_matches (Ts, Us) Vartab.empty) handle Type.TYPE_MATCH => NONE); |
50 |
52 |
51 |
53 |
52 (* datatype defs *) |
54 (* datatype defs *) |
53 |
55 |
54 type spec = {is_def: bool, thyname: string, name: string, lhs: args, rhs: (string * args) list}; |
56 type spec = {is_def: bool, name: string, lhs: args, rhs: (string * args) list}; |
55 |
57 |
56 type def = |
58 type def = |
57 {specs: spec Inttab.table, (*source specifications*) |
59 {specs: spec Inttab.table, (*source specifications*) |
58 restricts: (args * string) list, (*global restrictions imposed by incomplete patterns*) |
60 restricts: (args * string) list, (*global restrictions imposed by incomplete patterns*) |
59 reducts: (args * (string * args) list) list}; (*specifications as reduction system*) |
61 reducts: (args * (string * args) list) list}; (*specifications as reduction system*) |
72 fun lookup_list which defs c = |
74 fun lookup_list which defs c = |
73 (case Symtab.lookup defs c of |
75 (case Symtab.lookup defs c of |
74 SOME (def: def) => which def |
76 SOME (def: def) => which def |
75 | NONE => []); |
77 | NONE => []); |
76 |
78 |
77 fun specifications_of (Defs defs) = lookup_list (Inttab.dest o #specs) defs; |
79 fun specifications_of (Defs defs) = lookup_list (map snd o Inttab.dest o #specs) defs; |
|
80 fun all_specifications_of (Defs defs) = |
|
81 ((map o apsnd) (map snd o Inttab.dest o #specs) o Symtab.dest) defs; |
78 val restricts_of = lookup_list #restricts; |
82 val restricts_of = lookup_list #restricts; |
79 val reducts_of = lookup_list #reducts; |
83 val reducts_of = lookup_list #reducts; |
80 |
84 |
81 fun dest (Defs defs) = |
85 fun dest (Defs defs) = |
82 let |
86 let |
195 end; |
199 end; |
196 |
200 |
197 |
201 |
198 (* define *) |
202 (* define *) |
199 |
203 |
200 fun define pp unchecked is_def thyname name (c, args) deps (Defs defs) = |
204 fun define pp unchecked is_def name (c, args) deps (Defs defs) = |
201 let |
205 let |
202 val restr = |
206 val restr = |
203 if plain_args args orelse |
207 if plain_args args orelse |
204 (case args of [Type (a, rec_args)] => plain_args rec_args | _ => false) |
208 (case args of [Type (a, rec_args)] => plain_args rec_args | _ => false) |
205 then [] else [(args, name)]; |
209 then [] else [(args, name)]; |
206 val spec = |
210 val spec = |
207 (serial (), {is_def = is_def, thyname = thyname, name = name, lhs = args, rhs = deps}); |
211 (serial (), {is_def = is_def, name = name, lhs = args, rhs = deps}); |
208 val defs' = defs |> update_specs c spec; |
212 val defs' = defs |> update_specs c spec; |
209 in Defs (defs' |> (if unchecked then I else dependencies pp (c, args) restr deps)) end; |
213 in Defs (defs' |> (if unchecked then I else dependencies pp (c, args) restr deps)) end; |
210 |
214 |
211 end; |
215 end; |