src/HOL/List.thy
author clasohm
Fri, 03 Mar 1995 12:02:25 +0100
changeset 923 ff1574a81019
child 965 24eef3860714
permissions -rw-r--r--
new version of HOL with curried function application
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     1
(*  Title:      HOL/List.thy
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     3
    Author:     Tobias Nipkow
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1994 TU Muenchen
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
Definition of type 'a list as a datatype. This allows primrec to work.
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
List = Arith +
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
datatype 'a list = "[]" ("[]") | "#"('a,'a list) (infixr 65)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    13
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    14
consts
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    16
  null      :: "'a list => bool"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    17
  hd        :: "'a list => 'a"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
  tl,ttl    :: "'a list => 'a list"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
  mem       :: "['a, 'a list] => bool"			(infixl 55)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    20
  list_all  :: "('a => bool) => ('a list => bool)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    21
  map       :: "('a=>'b) => ('a list => 'b list)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    22
  "@"	    :: "['a list, 'a list] => 'a list"		(infixr 65)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    23
  filter    :: "['a => bool, 'a list] => 'a list"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
  foldl     :: "[['b,'a] => 'b, 'b, 'a list] => 'b"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    25
  length    :: "'a list => nat"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    26
  flat      :: "'a list list => 'a list"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    27
  nth       :: "[nat, 'a list] => 'a"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    28
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
syntax
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    30
  (* list Enumeration *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    31
  "@list"   :: "args => 'a list"                        ("[(_)]")
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
  (* Special syntax for list_all and filter *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
  "@Alls"	:: "[idt, 'a list, bool] => bool"	("(2Alls _:_./ _)" 10)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    35
  "@filter"	:: "[idt, 'a list, bool] => 'a list"	("(1[_:_ ./ _])")
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    36
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
translations
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
  "[x, xs]"     == "x#[xs]"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    39
  "[x]"         == "x#[]"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
  "[x:xs . P]"	== "filter (%x.P) xs"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
  "Alls x:xs.P"	== "list_all (%x.P) xs"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    43
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
primrec null list
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    45
  null_Nil "null([]) = True"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    46
  null_Cons "null(x#xs) = False"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    47
primrec hd list
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    48
  hd_Nil  "hd([]) = (@x.False)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    49
  hd_Cons "hd(x#xs) = x"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    50
primrec tl list
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    51
  tl_Nil  "tl([]) = (@x.False)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    52
  tl_Cons "tl(x#xs) = xs"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    53
primrec ttl list
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    54
  (* a "total" version of tl: *)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
  ttl_Nil  "ttl([]) = []"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
  ttl_Cons "ttl(x#xs) = xs"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    57
primrec "op mem" list
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
  mem_Nil  "x mem [] = False"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    59
  mem_Cons "x mem (y#ys) = if (y=x) True (x mem ys)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
primrec list_all list
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    61
  list_all_Nil  "list_all P [] = True"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    62
  list_all_Cons "list_all P (x#xs) = (P(x) & list_all P xs)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
primrec map list
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    64
  map_Nil  "map f [] = []"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    65
  map_Cons "map f (x#xs) = f(x)#map f xs"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
primrec "op @" list
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
  append_Nil  "[] @ ys = ys"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    68
  append_Cons "(x#xs)@ys = x#(xs@ys)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    69
primrec filter list
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
  filter_Nil  "filter P [] = []"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    71
  filter_Cons "filter P (x#xs) = if (P x) (x#filter P xs) (filter P xs)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    72
primrec foldl list
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    73
  foldl_Nil  "foldl f a [] = a"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    74
  foldl_Cons "foldl f a (x#xs) = foldl f (f a x) xs"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    75
primrec length list
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    76
  length_Nil  "length([]) = 0"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    77
  length_Cons "length(x#xs) = Suc(length(xs))"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
primrec flat list
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    79
  flat_Nil  "flat([]) = []"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    80
  flat_Cons "flat(x#xs) = x @ flat(xs)"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    81
defs
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    82
  nth_def "nth(n) == nat_rec n hd (%m r xs. r(tl(xs)))"
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    83
end