src/HOL/Tools/TFL/tfl.ML
changeset 35799 7adb03f27b28
parent 35666 6fd0ca1a3966
child 36610 bafd82950e24
equal deleted inserted replaced
35798:fd1bb29f8170 35799:7adb03f27b28
   358  *
   358  *
   359  *---------------------------------------------------------------------------*)
   359  *---------------------------------------------------------------------------*)
   360 
   360 
   361 
   361 
   362 (*For Isabelle, the lhs of a definition must be a constant.*)
   362 (*For Isabelle, the lhs of a definition must be a constant.*)
   363 fun legacy_const_def sign (c, Ty, rhs) =
   363 fun const_def sign (c, Ty, rhs) =
   364   singleton (Syntax.check_terms (ProofContext.init sign))
   364   singleton (Syntax.check_terms (ProofContext.init sign))
   365     (Sign.intern_term sign (Const("==",dummyT) $ Const(c,Ty) $ rhs));
   365     (Const("==",dummyT) $ Const(c,Ty) $ rhs);
   366 
   366 
   367 (*Make all TVars available for instantiation by adding a ? to the front*)
   367 (*Make all TVars available for instantiation by adding a ? to the front*)
   368 fun poly_tvars (Type(a,Ts)) = Type(a, map (poly_tvars) Ts)
   368 fun poly_tvars (Type(a,Ts)) = Type(a, map (poly_tvars) Ts)
   369   | poly_tvars (TFree (a,sort)) = TVar (("?" ^ a, 0), sort)
   369   | poly_tvars (TFree (a,sort)) = TVar (("?" ^ a, 0), sort)
   370   | poly_tvars (TVar ((a,i),sort)) = TVar (("?" ^ a, i+1), sort);
   370   | poly_tvars (TVar ((a,i),sort)) = TVar (("?" ^ a, i+1), sort);
   374       val {lhs=f, rhs} = S.dest_eq f_eq_wfrec_R_M
   374       val {lhs=f, rhs} = S.dest_eq f_eq_wfrec_R_M
   375       val (fname,_) = dest_Free f
   375       val (fname,_) = dest_Free f
   376       val (wfrec,_) = S.strip_comb rhs
   376       val (wfrec,_) = S.strip_comb rhs
   377 in
   377 in
   378 fun wfrec_definition0 thy fid R (functional as Abs(x, Ty, _)) =
   378 fun wfrec_definition0 thy fid R (functional as Abs(x, Ty, _)) =
   379  let val def_name = if x<>fid then
   379  let val def_name = Long_Name.base_name fid ^ "_def"
   380                         raise TFL_ERR "wfrec_definition0"
       
   381                                       ("Expected a definition of " ^
       
   382                                              quote fid ^ " but found one of " ^
       
   383                                       quote x)
       
   384                     else x ^ "_def"
       
   385      val wfrec_R_M =  map_types poly_tvars
   380      val wfrec_R_M =  map_types poly_tvars
   386                           (wfrec $ map_types poly_tvars R)
   381                           (wfrec $ map_types poly_tvars R)
   387                       $ functional
   382                       $ functional
   388      val def_term = legacy_const_def thy (x, Ty, wfrec_R_M)
   383      val def_term = const_def thy (fid, Ty, wfrec_R_M)
   389      val ([def], thy') = PureThy.add_defs false [Thm.no_attributes (Binding.name def_name, def_term)] thy
   384      val ([def], thy') =
       
   385       PureThy.add_defs false [Thm.no_attributes (Binding.name def_name, def_term)] thy
   390  in (thy', def) end;
   386  in (thy', def) end;
   391 end;
   387 end;
   392 
   388 
   393 
   389 
   394 
   390 
   538                                          thy proto_def')
   534                                          thy proto_def')
   539                            else ()
   535                            else ()
   540      val {lhs,rhs} = S.dest_eq proto_def'
   536      val {lhs,rhs} = S.dest_eq proto_def'
   541      val (c,args) = S.strip_comb lhs
   537      val (c,args) = S.strip_comb lhs
   542      val (name,Ty) = dest_atom c
   538      val (name,Ty) = dest_atom c
   543      val defn = legacy_const_def thy (name, Ty, S.list_mk_abs (args,rhs))
   539      val defn = const_def thy (name, Ty, S.list_mk_abs (args,rhs))
   544      val ([def0], theory) =
   540      val ([def0], theory) =
   545        thy
   541        thy
   546        |> PureThy.add_defs false
   542        |> PureThy.add_defs false
   547             [Thm.no_attributes (Binding.name (fid ^ "_def"), defn)]
   543             [Thm.no_attributes (Binding.name (fid ^ "_def"), defn)]
   548      val def = Thm.freezeT def0;
   544      val def = Thm.freezeT def0;