src/Doc/Typeclass_Hierarchy/Setup.thy
author wenzelm
Sun, 06 Jan 2019 15:04:34 +0100
changeset 69605 a96320074298
parent 69597 ff784d5a5bfb
child 74245 282cd3aa6cc6
permissions -rw-r--r--
isabelle update -u path_cartouches;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     1
theory Setup
66453
cc19f7ca2ed6 session-qualified theory imports: isabelle imports -U -i -d '~~/src/Benchmarks' -a;
wenzelm
parents: 63555
diff changeset
     2
imports Complex_Main "HOL-Library.Multiset" "HOL-Library.Lattice_Syntax"
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     3
begin
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     4
69605
a96320074298 isabelle update -u path_cartouches;
wenzelm
parents: 69597
diff changeset
     5
ML_file \<open>../antiquote_setup.ML\<close>
a96320074298 isabelle update -u path_cartouches;
wenzelm
parents: 69597
diff changeset
     6
ML_file \<open>../more_antiquote.ML\<close>
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     7
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     8
attribute_setup all =
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
     9
  \<open>Scan.succeed (Thm.rule_attribute [] (K Drule.forall_intr_vars))\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    10
  "quantified schematic vars"
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    11
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    12
setup \<open>Config.put_global Printer.show_type_emphasis false\<close>
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    13
63555
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    14
setup \<open>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    15
let
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    16
  fun strip_all t =
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    17
    if Logic.is_all t
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    18
    then
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    19
      case snd (dest_comb t) of Abs (w, T, t') =>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    20
        strip_all t' |>> cons (w, T)
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    21
    else ([], t);
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    22
  fun frugal (w, T as TFree (v, sort)) visited =
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    23
        if member (op =) visited v
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    24
        then ((w, dummyT), visited) else ((w, T), v :: visited)
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    25
    | frugal (w, T) visited = ((w, dummyT), visited);
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    26
  fun frugal_sorts t =
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    27
    let
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    28
      val (vTs, body) = strip_all t
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    29
      val (vTs', _) = fold_map frugal vTs [];
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    30
    in Logic.list_all (vTs', map_types (K dummyT) body) end;
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    31
in
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 66453
diff changeset
    32
  Term_Style.setup \<^binding>\<open>frugal_sorts\<close>
63555
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    33
    (Scan.succeed (K frugal_sorts))
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    34
end
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    35
\<close>
d00db72d8697 more on type class hierarchy
haftmann
parents: 63026
diff changeset
    36
63026
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    37
declare [[show_sorts]]
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    38
9a9c2d846d4a fragment of a HOL type class primer
haftmann
parents:
diff changeset
    39
end