src/HOL/ex/LFilter.thy
changeset 2984 b1a5455f0332
equal deleted inserted replaced
2983:f914a1663b2a 2984:b1a5455f0332
       
     1 (*  Title:      HOL/LList.thy
       
     2     ID:         $Id$
       
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
       
     4     Copyright   1997  University of Cambridge
       
     5 
       
     6 The "filter" functional for coinductive lists
       
     7   --defined by a combination of induction and coinduction
       
     8 *)
       
     9 
       
    10 LFilter = LList + Relation +
       
    11 
       
    12 consts
       
    13   findRel	:: "('a => bool) => ('a llist * 'a llist)set"
       
    14 
       
    15 inductive "findRel p"
       
    16   intrs
       
    17     found  "p x ==> (LCons x l, LCons x l) : findRel p"
       
    18     seek   "[| ~p x;  (l,l') : findRel p |] ==> (LCons x l, l') : findRel p"
       
    19 
       
    20 constdefs
       
    21   find		:: ['a => bool, 'a llist] => 'a llist
       
    22     "find p l == @l'. (l,l'): findRel p | (l' = LNil & l ~: Domain(findRel p))"
       
    23 
       
    24   lfilter	:: ['a => bool, 'a llist] => 'a llist
       
    25     "lfilter p l == llist_corec l (%l. case find p l of
       
    26                                             LNil => Inl ()
       
    27                                           | LCons y z => Inr(y,z))"
       
    28 
       
    29 end