src/HOL/MiniML/Maybe.thy
author webertj
Wed, 10 Mar 2004 22:33:48 +0100
changeset 14456 cca28ec5f9a6
parent 14422 b8da5f258b04
permissions -rw-r--r--
support for non-recursive IDTs, The, arbitrary, Hilbert_Choice.Eps
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     1
(* Title:     HOL/MiniML/Maybe.thy
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     2
   ID:        $Id$
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 1557
diff changeset
     3
   Author:    Wolfgang Naraschewski and Tobias Nipkow
477c05586286 The new version of MiniML including "let".
nipkow
parents: 1557
diff changeset
     4
   Copyright  1996 TU Muenchen
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     5
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     6
Universal error monad.
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     7
*)
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
     8
14422
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
     9
theory Maybe = Main:
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    10
1557
fe30812f5b5e added constdefs section
clasohm
parents: 1400
diff changeset
    11
constdefs
14422
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    12
  option_bind :: "['a option, 'a => 'b option] => 'b option"
2525
477c05586286 The new version of MiniML including "let".
nipkow
parents: 1557
diff changeset
    13
  "option_bind m f == case m of None => None | Some r => f r"
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    14
14422
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    15
syntax "@option_bind" :: "[pttrns,'a option,'b] => 'c" ("(_ := _;//_)" 0)
3842
b55686a7b22c fixed dots;
wenzelm
parents: 2525
diff changeset
    16
translations "P := E; F" == "option_bind E (%P. F)"
1400
5d909faf0e04 Introduced Monad syntax Pat := Val; Cont
nipkow
parents: 1376
diff changeset
    17
14422
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    18
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    19
(* constructor laws for option_bind *)
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    20
lemma option_bind_Some: "option_bind (Some s) f = (f s)"
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    21
apply (unfold option_bind_def)
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    22
apply (simp (no_asm))
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    23
done
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    24
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    25
lemma option_bind_None: "option_bind None f = None"
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    26
apply (unfold option_bind_def)
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    27
apply (simp (no_asm))
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    28
done
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    29
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    30
declare option_bind_Some [simp] option_bind_None [simp]
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    31
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    32
(* expansion of option_bind *)
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    33
lemma split_option_bind: "P(option_bind res f) =  
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    34
          ((res = None --> P None) & (!s. res = Some s --> P(f s)))"
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    35
apply (unfold option_bind_def)
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    36
apply (rule option.split)
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    37
done
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    38
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    39
lemma option_bind_eq_None: 
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    40
  "((option_bind m f) = None) = ((m=None) | (? p. m = Some p & f p = None))"
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    41
apply (simp (no_asm) split add: split_option_bind)
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    42
done
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    43
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    44
declare option_bind_eq_None [simp]
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    45
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    46
(* auxiliary lemma *)
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    47
lemma rotate_Some: "(y = Some x) = (Some x = y)"
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    48
apply ( simp (no_asm) add: eq_sym_conv)
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    49
done
b8da5f258b04 converted to Isar
kleing
parents: 12919
diff changeset
    50
1300
c7a8f374339b New theory: type inference for let-free MiniML
nipkow
parents:
diff changeset
    51
end