src/Pure/zterm.ML
changeset 80580 78106701061c
parent 80579 69cf3c308d6c
child 80581 7b6c4595d122
equal deleted inserted replaced
80579:69cf3c308d6c 80580:78106701061c
   249   exception BAD_INST of ((indexname * ztyp) * zterm) list
   249   exception BAD_INST of ((indexname * ztyp) * zterm) list
   250   val map_proof: {hyps: bool} -> ztyp Same.operation -> zterm Same.operation -> zproof -> zproof
   250   val map_proof: {hyps: bool} -> ztyp Same.operation -> zterm Same.operation -> zproof -> zproof
   251   val map_proof_types: {hyps: bool} -> ztyp Same.operation -> zproof -> zproof
   251   val map_proof_types: {hyps: bool} -> ztyp Same.operation -> zproof -> zproof
   252   val map_class_proof: (ztyp * class, zproof) Same.function -> zproof -> zproof
   252   val map_class_proof: (ztyp * class, zproof) Same.function -> zproof -> zproof
   253   val ztyp_of: typ -> ztyp
   253   val ztyp_of: typ -> ztyp
       
   254   val typ_of_tvar: indexname * sort -> typ
       
   255   val typ_of: ztyp -> typ
   254   val zterm_cache: theory -> {zterm: term -> zterm, ztyp: typ -> ztyp}
   256   val zterm_cache: theory -> {zterm: term -> zterm, ztyp: typ -> ztyp}
   255   val zterm_of: theory -> term -> zterm
   257   val zterm_of: theory -> term -> zterm
   256   val typ_of_tvar: indexname * sort -> typ
       
   257   val typ_of: ztyp -> typ
       
   258   val term_of: theory -> zterm -> term
   258   val term_of: theory -> zterm -> term
   259   val beta_norm_term_same: zterm Same.operation
   259   val beta_norm_term_same: zterm Same.operation
   260   val beta_norm_proof_same: zproof Same.operation
   260   val beta_norm_proof_same: zproof Same.operation
   261   val beta_norm_prooft_same: zproof -> zproof
   261   val beta_norm_prooft_same: zproof -> zproof
   262   val beta_norm_term: zterm -> zterm
   262   val beta_norm_term: zterm -> zterm
   575             handle Same.SAME => ZAppp (p, proof q))
   575             handle Same.SAME => ZAppp (p, proof q))
   576       | proof _ = raise Same.SAME;
   576       | proof _ = raise Same.SAME;
   577   in Same.commit proof end;
   577   in Same.commit proof end;
   578 
   578 
   579 
   579 
   580 (* convert ztyp / zterm vs. regular typ / term *)
   580 (* convert ztyp vs. regular typ *)
   581 
   581 
   582 fun ztyp_of (TFree (a, S)) = ZTVar ((a, ~1), S)
   582 fun ztyp_of (TFree (a, S)) = ZTVar ((a, ~1), S)
   583   | ztyp_of (TVar v) = ZTVar v
   583   | ztyp_of (TVar v) = ZTVar v
   584   | ztyp_of (Type ("fun", [T, U])) = ZFun (ztyp_of T, ztyp_of U)
   584   | ztyp_of (Type ("fun", [T, U])) = ZFun (ztyp_of T, ztyp_of U)
   585   | ztyp_of (Type ("prop", [])) = ZProp
   585   | ztyp_of (Type ("prop", [])) = ZProp
   586   | ztyp_of (Type (c, [])) = ZType0 c
   586   | ztyp_of (Type (c, [])) = ZType0 c
   587   | ztyp_of (Type (c, [T])) = ZType1 (c, ztyp_of T)
   587   | ztyp_of (Type (c, [T])) = ZType1 (c, ztyp_of T)
   588   | ztyp_of (Type (c, ts)) = ZType (c, map ztyp_of ts);
   588   | ztyp_of (Type (c, ts)) = ZType (c, map ztyp_of ts);
   589 
   589 
       
   590 fun typ_of_tvar ((a, ~1), S) = TFree (a, S)
       
   591   | typ_of_tvar v = TVar v;
       
   592 
       
   593 fun typ_of (ZTVar v) = typ_of_tvar v
       
   594   | typ_of (ZFun (T, U)) = typ_of T --> typ_of U
       
   595   | typ_of ZProp = propT
       
   596   | typ_of (ZType0 c) = Type (c, [])
       
   597   | typ_of (ZType1 (c, T)) = Type (c, [typ_of T])
       
   598   | typ_of (ZType (c, Ts)) = Type (c, map typ_of Ts);
       
   599 
   590 fun ztyp_cache () = #apply (Typtab.unsynchronized_cache ztyp_of);
   600 fun ztyp_cache () = #apply (Typtab.unsynchronized_cache ztyp_of);
       
   601 fun typ_cache () = #apply (ZTypes.unsynchronized_cache typ_of);
       
   602 
       
   603 
       
   604 (* convert zterm vs. regular term *)
   591 
   605 
   592 fun zterm_cache thy =
   606 fun zterm_cache thy =
   593   let
   607   let
   594     val typargs = Consts.typargs (Sign.consts_of thy);
   608     val typargs = Consts.typargs (Sign.consts_of thy);
   595 
   609 
   609             SOME (T, c) => OFCLASS (ztyp T, c)
   623             SOME (T, c) => OFCLASS (ztyp T, c)
   610           | NONE => ZApp (zterm t, zterm u));
   624           | NONE => ZApp (zterm t, zterm u));
   611   in {ztyp = ztyp, zterm = zterm} end;
   625   in {ztyp = ztyp, zterm = zterm} end;
   612 
   626 
   613 val zterm_of = #zterm o zterm_cache;
   627 val zterm_of = #zterm o zterm_cache;
   614 
       
   615 fun typ_of_tvar ((a, ~1), S) = TFree (a, S)
       
   616   | typ_of_tvar v = TVar v;
       
   617 
       
   618 fun typ_of (ZTVar v) = typ_of_tvar v
       
   619   | typ_of (ZFun (T, U)) = typ_of T --> typ_of U
       
   620   | typ_of ZProp = propT
       
   621   | typ_of (ZType0 c) = Type (c, [])
       
   622   | typ_of (ZType1 (c, T)) = Type (c, [typ_of T])
       
   623   | typ_of (ZType (c, Ts)) = Type (c, map typ_of Ts);
       
   624 
       
   625 fun typ_cache () = #apply (ZTypes.unsynchronized_cache typ_of);
       
   626 
   628 
   627 fun term_of thy =
   629 fun term_of thy =
   628   let
   630   let
   629     val instance = Consts.instance (Sign.consts_of thy);
   631     val instance = Consts.instance (Sign.consts_of thy);
   630 
   632