TFL/tfl.ML
changeset 15531 08c8dad8e399
parent 14820 3f80d6510ee9
child 15570 8d8c70b41bab
equal deleted inserted replaced
15530:6f43714517ee 15531:08c8dad8e399
   258           end
   258           end
   259      else
   259      else
   260      let val pty as Type (ty_name,_) = type_of p
   260      let val pty as Type (ty_name,_) = type_of p
   261      in
   261      in
   262      case (ty_info ty_name)
   262      case (ty_info ty_name)
   263      of None => mk_case_fail("Not a known datatype: "^ty_name)
   263      of NONE => mk_case_fail("Not a known datatype: "^ty_name)
   264       | Some{case_const,constructors} =>
   264       | SOME{case_const,constructors} =>
   265         let
   265         let
   266             val case_const_name = #1(dest_Const case_const)
   266             val case_const_name = #1(dest_Const case_const)
   267             val nrows = List.concat (map (expand constructors pty) rows)
   267             val nrows = List.concat (map (expand constructors pty) rows)
   268             val subproblems = divide(constructors, pty, range_ty, nrows)
   268             val subproblems = divide(constructors, pty, range_ty, nrows)
   269             val groups      = map #group subproblems
   269             val groups      = map #group subproblems
   369  *---------------------------------------------------------------------------*)
   369  *---------------------------------------------------------------------------*)
   370 
   370 
   371 
   371 
   372 (*For Isabelle, the lhs of a definition must be a constant.*)
   372 (*For Isabelle, the lhs of a definition must be a constant.*)
   373 fun mk_const_def sign (Name, Ty, rhs) =
   373 fun mk_const_def sign (Name, Ty, rhs) =
   374     Sign.infer_types (Sign.pp sign) sign (K None) (K None) [] false
   374     Sign.infer_types (Sign.pp sign) sign (K NONE) (K NONE) [] false
   375                ([Const("==",dummyT) $ Const(Name,Ty) $ rhs], propT)
   375                ([Const("==",dummyT) $ Const(Name,Ty) $ rhs], propT)
   376     |> #1;
   376     |> #1;
   377 
   377 
   378 (*Make all TVars available for instantiation by adding a ? to the front*)
   378 (*Make all TVars available for instantiation by adding a ? to the front*)
   379 fun poly_tvars (Type(a,Ts)) = Type(a, map (poly_tvars) Ts)
   379 fun poly_tvars (Type(a,Ts)) = Type(a, map (poly_tvars) Ts)
   621 fun alpha_ex_unroll (xlist, tm) =
   621 fun alpha_ex_unroll (xlist, tm) =
   622   let val (qvars,body) = S.strip_exists tm
   622   let val (qvars,body) = S.strip_exists tm
   623       val vlist = #2(S.strip_comb (S.rhs body))
   623       val vlist = #2(S.strip_comb (S.rhs body))
   624       val plist = ListPair.zip (vlist, xlist)
   624       val plist = ListPair.zip (vlist, xlist)
   625       val args = map (fn qv => the (gen_assoc (op aconv) (plist, qv))) qvars
   625       val args = map (fn qv => the (gen_assoc (op aconv) (plist, qv))) qvars
   626                    handle Library.OPTION => sys_error
   626                    handle Option => sys_error
   627                        "TFL fault [alpha_ex_unroll]: no correspondence"
   627                        "TFL fault [alpha_ex_unroll]: no correspondence"
   628       fun build ex      []   = []
   628       fun build ex      []   = []
   629         | build (_$rex) (v::rst) =
   629         | build (_$rex) (v::rst) =
   630            let val ex1 = betapply(rex, v)
   630            let val ex1 = betapply(rex, v)
   631            in  ex1 :: build ex1 rst
   631            in  ex1 :: build ex1 rst
   664           end
   664           end
   665      else                     (* column 0 is all constructors *)
   665      else                     (* column 0 is all constructors *)
   666      let val Type (ty_name,_) = type_of p
   666      let val Type (ty_name,_) = type_of p
   667      in
   667      in
   668      case (ty_info ty_name)
   668      case (ty_info ty_name)
   669      of None => fail("Not a known datatype: "^ty_name)
   669      of NONE => fail("Not a known datatype: "^ty_name)
   670       | Some{constructors,nchotomy} =>
   670       | SOME{constructors,nchotomy} =>
   671         let val thm' = R.ISPEC (tych u) nchotomy
   671         let val thm' = R.ISPEC (tych u) nchotomy
   672             val disjuncts = S.strip_disj (concl thm')
   672             val disjuncts = S.strip_disj (concl thm')
   673             val subproblems = divide(constructors, rows)
   673             val subproblems = divide(constructors, rows)
   674             val groups      = map #group subproblems
   674             val groups      = map #group subproblems
   675             and new_formals = map #new_formals subproblems
   675             and new_formals = map #new_formals subproblems