ProgTutorial/General.thy
changeset 323 92f6a772e013
parent 319 6bce4acf7f2a
child 328 c0cae24b9d46
equal deleted inserted replaced
322:2b7c08d90e2e 323:92f6a772e013
     1 theory General
     1 theory General
     2 imports Base FirstSteps
     2 imports Base FirstSteps
     3 begin
     3 begin
     4 
     4 
     5 chapter {* General Infrastructure *}
     5 chapter {* Isabelle -- The Good, the Bad and the Ugly *}
     6 
     6 
     7 text {*
     7 text {*
     8   Isabelle is build around a few central ideas. One is the LCF-approach to
     8   Isabelle is build around a few central ideas. One is the LCF-approach to
     9   theorem proving where there is a small trusted core and everything else is
     9   theorem proving where there is a small trusted core and everything else is
    10   build on top of this trusted core.
    10   build on top of this trusted core.
  1242   @{ML_type local_theory} is identical to the type of \emph{proof contexts}
  1242   @{ML_type local_theory} is identical to the type of \emph{proof contexts}
  1243   @{ML_type "Proof.context"}, although not every proof context constitutes a
  1243   @{ML_type "Proof.context"}, although not every proof context constitutes a
  1244   valid local theory.
  1244   valid local theory.
  1245 *}
  1245 *}
  1246 
  1246 
  1247 (*
       
  1248 ML{*signature UNIVERSAL_TYPE =
       
  1249 sig
       
  1250   type t
       
  1251 
       
  1252   val embed: unit -> ('a -> t) * (t -> 'a option)
       
  1253 end*}
       
  1254 
       
  1255 ML{*structure U:> UNIVERSAL_TYPE =
       
  1256    struct
       
  1257       type t = exn
       
  1258 
       
  1259       fun 'a embed () =
       
  1260          let
       
  1261             exception E of 'a
       
  1262             fun project (e: t): 'a option =
       
  1263                case e of
       
  1264                   E a => SOME a
       
  1265                 | _ => NONE
       
  1266          in
       
  1267             (E, project)
       
  1268          end
       
  1269    end*}
       
  1270 
       
  1271 text {*
       
  1272   The idea is that type t is the universal type and that each call to embed
       
  1273   returns a new pair of functions (inject, project), where inject embeds a
       
  1274   value into the universal type and project extracts the value from the
       
  1275   universal type. A pair (inject, project) returned by embed works together in
       
  1276   that project u will return SOME v if and only if u was created by inject
       
  1277   v. If u was created by a different function inject', then project returns
       
  1278   NONE.
       
  1279 
       
  1280   in library.ML
       
  1281 *}
       
  1282 
       
  1283 ML_val{*structure Object = struct type T = exn end; *}
       
  1284 
       
  1285 ML{*functor Test (U: UNIVERSAL_TYPE): sig end =
       
  1286    struct
       
  1287       val (intIn: int -> U.t, intOut) = U.embed ()
       
  1288       val r: U.t ref = ref (intIn 13)
       
  1289       val s1 =
       
  1290          case intOut (!r) of
       
  1291             NONE => "NONE"
       
  1292           | SOME i => Int.toString i
       
  1293       val (realIn: real -> U.t, realOut) = U.embed ()
       
  1294       val () = r := realIn 13.0
       
  1295       val s2 =
       
  1296          case intOut (!r) of
       
  1297             NONE => "NONE"
       
  1298           | SOME i => Int.toString i
       
  1299       val s3 =
       
  1300          case realOut (!r) of
       
  1301             NONE => "NONE"
       
  1302           | SOME x => Real.toString x
       
  1303       val () = tracing (concat [s1, " ", s2, " ", s3, "\n"])
       
  1304    end*}
       
  1305 
       
  1306 ML_val{*structure t = Test(U) *} 
       
  1307 
       
  1308 ML_val{*structure Datatab = TableFun(type key = int val ord = int_ord);*}
       
  1309 
       
  1310 ML {* LocalTheory.restore *}
       
  1311 ML {* LocalTheory.set_group *}
       
  1312 *)
       
  1313 
       
  1314 section {* Storing Theorems\label{sec:storing} (TBD) *}
  1247 section {* Storing Theorems\label{sec:storing} (TBD) *}
  1315 
  1248 
  1316 text {* @{ML_ind  add_thms_dynamic in PureThy} *}
  1249 text {* @{ML_ind  add_thms_dynamic in PureThy} *}
  1317 
  1250 
  1318 local_setup %gray {* 
  1251 local_setup %gray {*