src/HOL/Tools/choice_specification.ML
changeset 35845 e5980f0ad025
parent 35807 e4d1b5cbd429
child 35856 f81557a124d5
equal deleted inserted replaced
35844:65258d2c3214 35845:e5980f0ad025
    88 fun collect_consts (        t $ u,tms) = collect_consts (u,collect_consts (t,tms))
    88 fun collect_consts (        t $ u,tms) = collect_consts (u,collect_consts (t,tms))
    89   | collect_consts (   Abs(_,_,t),tms) = collect_consts (t,tms)
    89   | collect_consts (   Abs(_,_,t),tms) = collect_consts (t,tms)
    90   | collect_consts (tm as Const _,tms) = insert (op aconv) tm tms
    90   | collect_consts (tm as Const _,tms) = insert (op aconv) tm tms
    91   | collect_consts (            _,tms) = tms
    91   | collect_consts (            _,tms) = tms
    92 
    92 
    93 (* Complementing Type.varify... *)
    93 (* Complementing Type.varify_global... *)
    94 
    94 
    95 fun unvarify t fmap =
    95 fun unvarify_global t fmap =
    96     let
    96     let
    97         val fmap' = map Library.swap fmap
    97         val fmap' = map Library.swap fmap
    98         fun unthaw (f as (a, S)) =
    98         fun unthaw (f as (a, S)) =
    99             (case AList.lookup (op =) fmap' a of
    99             (case AList.lookup (op =) fmap' a of
   100                  NONE => TVar f
   100                  NONE => TVar f
   133         val props'' = map proc_single props'
   133         val props'' = map proc_single props'
   134         val frees = map snd props''
   134         val frees = map snd props''
   135         val prop  = myfoldr HOLogic.mk_conj (map fst props'')
   135         val prop  = myfoldr HOLogic.mk_conj (map fst props'')
   136         val cprop = cterm_of thy (HOLogic.mk_Trueprop prop)
   136         val cprop = cterm_of thy (HOLogic.mk_Trueprop prop)
   137 
   137 
   138         val (vmap, prop_thawed) = Type.varify [] prop
   138         val (vmap, prop_thawed) = Type.varify_global [] prop
   139         val thawed_prop_consts = collect_consts (prop_thawed,[])
   139         val thawed_prop_consts = collect_consts (prop_thawed,[])
   140         val (altcos,overloaded) = Library.split_list cos
   140         val (altcos,overloaded) = Library.split_list cos
   141         val (names,sconsts) = Library.split_list altcos
   141         val (names,sconsts) = Library.split_list altcos
   142         val consts = map (Syntax.read_term_global thy) sconsts
   142         val consts = map (Syntax.read_term_global thy) sconsts
   143         val _ = not (Library.exists (not o Term.is_Const) consts)
   143         val _ = not (Library.exists (not o Term.is_Const) consts)
   144           orelse error "Specification: Non-constant found as parameter"
   144           orelse error "Specification: Non-constant found as parameter"
   145 
   145 
   146         fun proc_const c =
   146         fun proc_const c =
   147             let
   147             let
   148                 val (_, c') = Type.varify [] c
   148                 val (_, c') = Type.varify_global [] c
   149                 val (cname,ctyp) = dest_Const c'
   149                 val (cname,ctyp) = dest_Const c'
   150             in
   150             in
   151                 case filter (fn t => let val (name,typ) = dest_Const t
   151                 case filter (fn t => let val (name,typ) = dest_Const t
   152                                      in name = cname andalso Sign.typ_equiv thy (typ, ctyp)
   152                                      in name = cname andalso Sign.typ_equiv thy (typ, ctyp)
   153                                      end) thawed_prop_consts of
   153                                      end) thawed_prop_consts of
   154                     [] => error ("Specification: No suitable instances of constant \"" ^ Syntax.string_of_term_global thy c ^ "\" found")
   154                     [] => error ("Specification: No suitable instances of constant \"" ^ Syntax.string_of_term_global thy c ^ "\" found")
   155                   | [cf] => unvarify cf vmap
   155                   | [cf] => unvarify_global cf vmap
   156                   | _ => error ("Specification: Several variations of \"" ^ Syntax.string_of_term_global thy c ^ "\" found (try applying explicit type constraints)")
   156                   | _ => error ("Specification: Several variations of \"" ^ Syntax.string_of_term_global thy c ^ "\" found (try applying explicit type constraints)")
   157             end
   157             end
   158         val proc_consts = map proc_const consts
   158         val proc_consts = map proc_const consts
   159         fun mk_exist c prop =
   159         fun mk_exist c prop =
   160             let
   160             let