src/HOL/Tools/datatype_package.ML
changeset 29270 0eade173f77e
parent 29064 70a61d58460e
child 29579 cb520b766e00
equal deleted inserted replaced
29269:5c25a2012975 29270:0eade173f77e
     1 (*  Title:      HOL/Tools/datatype_package.ML
     1 (*  Title:      HOL/Tools/datatype_package.ML
     2     ID:         $Id$
       
     3     Author:     Stefan Berghofer, TU Muenchen
     2     Author:     Stefan Berghofer, TU Muenchen
     4 
     3 
     5 Datatype package for Isabelle/HOL.
     4 Datatype package for Isabelle/HOL.
     6 *)
     5 *)
     7 
     6 
   490     fun no_constr (c, T) = error ("Bad constructor: "
   489     fun no_constr (c, T) = error ("Bad constructor: "
   491       ^ Sign.extern_const thy c ^ "::"
   490       ^ Sign.extern_const thy c ^ "::"
   492       ^ Syntax.string_of_typ_global thy T);
   491       ^ Syntax.string_of_typ_global thy T);
   493     fun type_of_constr (cT as (_, T)) =
   492     fun type_of_constr (cT as (_, T)) =
   494       let
   493       let
   495         val frees = typ_tfrees T;
   494         val frees = OldTerm.typ_tfrees T;
   496         val (tyco, vs) = ((apsnd o map) (dest_TFree) o dest_Type o snd o strip_type) T
   495         val (tyco, vs) = ((apsnd o map) (dest_TFree) o dest_Type o snd o strip_type) T
   497           handle TYPE _ => no_constr cT
   496           handle TYPE _ => no_constr cT
   498         val _ = if has_duplicates (eq_fst (op =)) vs then no_constr cT else ();
   497         val _ = if has_duplicates (eq_fst (op =)) vs then no_constr cT else ();
   499         val _ = if length frees <> length vs then no_constr cT else ();
   498         val _ = if length frees <> length vs then no_constr cT else ();
   500       in (tyco, (vs, cT)) end;
   499       in (tyco, (vs, cT)) end;
   581     fun prep_dt_spec (tvs, tname, mx, constrs) (dts', constr_syntax, sorts, i) =
   580     fun prep_dt_spec (tvs, tname, mx, constrs) (dts', constr_syntax, sorts, i) =
   582       let
   581       let
   583         fun prep_constr (cname, cargs, mx') (constrs, constr_syntax', sorts') =
   582         fun prep_constr (cname, cargs, mx') (constrs, constr_syntax', sorts') =
   584           let
   583           let
   585             val (cargs', sorts'') = Library.foldl (prep_typ tmp_thy) (([], sorts'), cargs);
   584             val (cargs', sorts'') = Library.foldl (prep_typ tmp_thy) (([], sorts'), cargs);
   586             val _ = (case fold (curry add_typ_tfree_names) cargs' [] \\ tvs of
   585             val _ = (case fold (curry OldTerm.add_typ_tfree_names) cargs' [] \\ tvs of
   587                 [] => ()
   586                 [] => ()
   588               | vs => error ("Extra type variables on rhs: " ^ commas vs))
   587               | vs => error ("Extra type variables on rhs: " ^ commas vs))
   589           in (constrs @ [((if flat_names then Sign.full_bname tmp_thy else
   588           in (constrs @ [((if flat_names then Sign.full_bname tmp_thy else
   590                 Sign.full_bname_path tmp_thy tname) (Syntax.const_name cname mx'),
   589                 Sign.full_bname_path tmp_thy tname) (Syntax.const_name cname mx'),
   591                    map (dtyp_of_typ new_dts) cargs')],
   590                    map (dtyp_of_typ new_dts) cargs')],