src/HOL/Library/Datatype_Records.thy
author Lars Hupel <lars.hupel@mytum.de>
Wed Feb 14 11:51:03 2018 +0100 (18 months ago)
changeset 67611 7929240e44d4
child 67618 3107dcea3493
permissions -rw-r--r--
records based on datatypes/BNF infrastructure
lars@67611
     1
section \<open>Records based on BNF/datatype machinery\<close>
lars@67611
     2
lars@67611
     3
theory Datatype_Records
lars@67611
     4
imports Main
lars@67611
     5
keywords "datatype_record" :: thy_decl
lars@67611
     6
begin
lars@67611
     7
lars@67611
     8
no_syntax
lars@67611
     9
  "_constify"           :: "id => ident"                        ("_")
lars@67611
    10
  "_constify"           :: "longid => ident"                    ("_")
lars@67611
    11
lars@67611
    12
  "_field_type"         :: "ident => type => field_type"        ("(2_ ::/ _)")
lars@67611
    13
  ""                    :: "field_type => field_types"          ("_")
lars@67611
    14
  "_field_types"        :: "field_type => field_types => field_types"    ("_,/ _")
lars@67611
    15
  "_record_type"        :: "field_types => type"                ("(3\<lparr>_\<rparr>)")
lars@67611
    16
  "_record_type_scheme" :: "field_types => type => type"        ("(3\<lparr>_,/ (2\<dots> ::/ _)\<rparr>)")
lars@67611
    17
lars@67611
    18
  "_field"              :: "ident => 'a => field"               ("(2_ =/ _)")
lars@67611
    19
  ""                    :: "field => fields"                    ("_")
lars@67611
    20
  "_fields"             :: "field => fields => fields"          ("_,/ _")
lars@67611
    21
  "_record"             :: "fields => 'a"                       ("(3\<lparr>_\<rparr>)")
lars@67611
    22
  "_record_scheme"      :: "fields => 'a => 'a"                 ("(3\<lparr>_,/ (2\<dots> =/ _)\<rparr>)")
lars@67611
    23
lars@67611
    24
  "_field_update"       :: "ident => 'a => field_update"        ("(2_ :=/ _)")
lars@67611
    25
  ""                    :: "field_update => field_updates"      ("_")
lars@67611
    26
  "_field_updates"      :: "field_update => field_updates => field_updates"  ("_,/ _")
lars@67611
    27
  "_record_update"      :: "'a => field_updates => 'b"          ("_/(3\<lparr>_\<rparr>)" [900, 0] 900)
lars@67611
    28
lars@67611
    29
no_syntax (ASCII)
lars@67611
    30
  "_record_type"        :: "field_types => type"                ("(3'(| _ |'))")
lars@67611
    31
  "_record_type_scheme" :: "field_types => type => type"        ("(3'(| _,/ (2... ::/ _) |'))")
lars@67611
    32
  "_record"             :: "fields => 'a"                       ("(3'(| _ |'))")
lars@67611
    33
  "_record_scheme"      :: "fields => 'a => 'a"                 ("(3'(| _,/ (2... =/ _) |'))")
lars@67611
    34
  "_record_update"      :: "'a => field_updates => 'b"          ("_/(3'(| _ |'))" [900, 0] 900)
lars@67611
    35
lars@67611
    36
(* copied and adapted from Record.thy *)
lars@67611
    37
lars@67611
    38
nonterminal
lars@67611
    39
  field and
lars@67611
    40
  fields and
lars@67611
    41
  field_update and
lars@67611
    42
  field_updates
lars@67611
    43
lars@67611
    44
syntax
lars@67611
    45
  "_constify"               :: "id => ident"                        ("_")
lars@67611
    46
  "_constify"               :: "longid => ident"                    ("_")
lars@67611
    47
lars@67611
    48
  "_datatype_field"         :: "ident => 'a => field"               ("(2_ =/ _)")
lars@67611
    49
  ""                        :: "field => fields"                    ("_")
lars@67611
    50
  "_datatype_fields"        :: "field => fields => fields"          ("_,/ _")
lars@67611
    51
  "_datatype_record"        :: "fields => 'a"                       ("(3\<lparr>_\<rparr>)")
lars@67611
    52
  "_datatype_field_update"  :: "ident => 'a => field_update"        ("(2_ :=/ _)")
lars@67611
    53
  ""                        :: "field_update => field_updates"      ("_")
lars@67611
    54
  "_datatype_field_updates" :: "field_update => field_updates => field_updates"  ("_,/ _")
lars@67611
    55
  "_datatype_record_update" :: "'a => field_updates => 'b"          ("_/(3\<lparr>_\<rparr>)" [900, 0] 900)
lars@67611
    56
lars@67611
    57
syntax (ASCII)
lars@67611
    58
  "_datatype_record"        :: "fields => 'a"                       ("(3'(| _ |'))")
lars@67611
    59
  "_datatype_record_scheme" :: "fields => 'a => 'a"                 ("(3'(| _,/ (2... =/ _) |'))")
lars@67611
    60
  "_datatype_record_update" :: "'a => field_updates => 'b"          ("_/(3'(| _ |'))" [900, 0] 900)
lars@67611
    61
lars@67611
    62
named_theorems datatype_record_update
lars@67611
    63
lars@67611
    64
ML_file "datatype_records.ML"
lars@67611
    65
setup \<open>Datatype_Records.setup\<close>
lars@67611
    66
lars@67611
    67
end