Datatype.ML
changeset 121 2536dfe47b75
parent 104 a0e6613dfbee
child 123 8bef44f9b237
equal deleted inserted replaced
120:19facfd773de 121:2536dfe47b75
   101 (*used for constructor parameters*)
   101 (*used for constructor parameters*)
   102 datatype dt_type = dtVar of string |
   102 datatype dt_type = dtVar of string |
   103                    dtTyp of dt_type list * string |
   103                    dtTyp of dt_type list * string |
   104                    dtRek of dt_type list * string;
   104                    dtRek of dt_type list * string;
   105 
   105 
   106 local open Syntax.Mixfix
   106 local open Syntax
   107            ThyParse
   107            ThyParse
   108       exception Impossible
   108       exception Impossible
   109 
   109 
   110 val is_Rek = (fn dtRek _ => true  |  _  => false);
   110 val is_Rek = (fn dtRek _ => true  |  _  => false);
   111 
   111 
   212 (* take datatype and eqns and return a properly type-instantiated 
   212 (* take datatype and eqns and return a properly type-instantiated 
   213    application of the prim-rec-combinator which solves eqns.
   213    application of the prim-rec-combinator which solves eqns.
   214 *)
   214 *)
   215 
   215 
   216 fun instant_types thy t =
   216 fun instant_types thy t =
   217 let val rs = Sign.rep_sg(sign_of thy);  
   217   fst (Sign.infer_types (sign_of thy) (K None) (K None) (t, TVar(("",0),[])));
   218 in  fst(Type.infer_types( #tsig rs,#const_tab rs, K None, K None
       
   219 		        , TVar(("",0),[]), t))
       
   220 end;
       
   221 
   218 
   222 in
   219 in
   223 
   220 
   224 fun add_datatype (typevars, tname, cons_list') thy = 
   221 fun add_datatype (typevars, tname, cons_list') thy = 
   225   let (*search for free type variables and convert recursive *)
   222   let (*search for free type variables and convert recursive *)
   503           val (fname,rfuns) = funs_from_eqns cons_list teqns
   500           val (fname,rfuns) = funs_from_eqns cons_list teqns
   504           val rhs = Abs(tname, dummyT,
   501           val rhs = Abs(tname, dummyT,
   505                         list_comb(rec_comb, Bound 0 :: rev rfuns))
   502                         list_comb(rec_comb, Bound 0 :: rev rfuns))
   506           val def = Const("==",dummyT) $ Const(fname,dummyT) $ rhs
   503           val def = Const("==",dummyT) $ Const(fname,dummyT) $ rhs
   507           val tdef = instant_types thy def
   504           val tdef = instant_types thy def
   508       in add_defns_i [(fname ^ "_def", tdef)] thy end;
   505       in add_defs_i [(fname ^ "_def", tdef)] thy end;
   509 
   506 
   510   in (thy
   507   in (thy
   511      |> add_types types
   508      |> add_types types
   512      |> add_arities arities
   509      |> add_arities arities
   513      |> add_consts consts
   510      |> add_consts consts