combinator List.those;
authorhaftmann
Wed, 13 Feb 2013 13:38:52 +0100
changeset 51096 60e4b75fefe1
parent 51095 7ae79f2e3cc7
child 51101 66d0298fc554
child 51102 358b27c56469
combinator List.those; simprule for case distinction on Option.map expression
src/HOL/List.thy
src/HOL/Option.thy
--- a/src/HOL/List.thy	Wed Feb 13 13:38:52 2013 +0100
+++ b/src/HOL/List.thy	Wed Feb 13 13:38:52 2013 +0100
@@ -162,6 +162,13 @@
 
 hide_const (open) find
 
+primrec those :: "'a option list \<Rightarrow> 'a list option"
+where
+"those [] = Some []" |
+"those (x # xs) = (case x of
+  None \<Rightarrow> None
+| Some y \<Rightarrow> Option.map (Cons y) (those xs))"
+
 primrec remove1 :: "'a \<Rightarrow> 'a list \<Rightarrow> 'a list" where
 "remove1 x [] = []" |
 "remove1 x (y # xs) = (if x = y then xs else y # remove1 x xs)"
--- a/src/HOL/Option.thy	Wed Feb 13 13:38:52 2013 +0100
+++ b/src/HOL/Option.thy	Wed Feb 13 13:38:52 2013 +0100
@@ -101,6 +101,10 @@
   qed
 qed
 
+lemma option_case_map [simp]:
+  "option_case g h (Option.map f x) = option_case g (h \<circ> f) x"
+  by (cases x) simp_all
+
 primrec bind :: "'a option \<Rightarrow> ('a \<Rightarrow> 'b option) \<Rightarrow> 'b option" where
 bind_lzero: "bind None f = None" |
 bind_lunit: "bind (Some x) f = f x"