src/HOL/Predicate.thy
changeset 33607 9b3c4e95380e
parent 33111 db5af7b86a2f
child 33622 24a91a380ee3
equal deleted inserted replaced
33606:2b27020ffcb2 33607:9b3c4e95380e
   800 fun yield (@{code Seq} f) = next (f ())
   800 fun yield (@{code Seq} f) = next (f ())
   801 and next @{code Empty} = NONE
   801 and next @{code Empty} = NONE
   802   | next (@{code Insert} (x, P)) = SOME (x, P)
   802   | next (@{code Insert} (x, P)) = SOME (x, P)
   803   | next (@{code Join} (P, xq)) = (case yield P
   803   | next (@{code Join} (P, xq)) = (case yield P
   804      of NONE => next xq
   804      of NONE => next xq
   805       | SOME (x, Q) => SOME (x, @{code Seq} (fn _ => @{code Join} (Q, xq))))
   805       | SOME (x, Q) => SOME (x, @{code Seq} (fn _ => @{code Join} (Q, xq))));
   806 
   806 
   807 fun anamorph f k x = (if k = 0 then ([], x)
   807 fun anamorph f k x = (if k = 0 then ([], x)
   808   else case f x
   808   else case f x
   809    of NONE => ([], x)
   809    of NONE => ([], x)
   810     | SOME (v, y) => let
   810     | SOME (v, y) => let
   811         val (vs, z) = anamorph f (k - 1) y
   811         val (vs, z) = anamorph f (k - 1) y
   812       in (v :: vs, z) end)
   812       in (v :: vs, z) end);
   813 
   813 
   814 fun yieldn P = anamorph yield P;
   814 fun yieldn P = anamorph yield P;
   815 
   815 
   816 fun map f = @{code map} f;
   816 fun map f = @{code map} f;
   817 
   817