Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. {-| Returns a list of repeated applications of `f`.
  2.  
  3. If `f` returns `Nothing` the iteration will stop. If it returns `Just y` then
  4. `y` will be added to the list and the iteration will continue with `f y`.
  5.  
  6. nextYear : Int -> Maybe Int
  7. nextYear year =
  8. if year >= 2030 then
  9. Nothing
  10. else
  11. Just (year + 1)
  12.  
  13. -- Will evaluate to [2010, 2011, ..., 2030]
  14. iterate nextYear 2010
  15. -}
  16. iterate : (a -> Maybe a) -> a -> List a
  17. iterate f x =
  18. case f x of
  19. Just x' -> x :: iterate f x'
  20. Nothing -> [x]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement