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