Skip to content

Instantly share code, notes, and snippets.

@chris-martin
Created March 2, 2021 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-martin/9a99e1c8a745f074968b28b523c43423 to your computer and use it in GitHub Desktop.
Save chris-martin/9a99e1c8a745f074968b28b523c43423 to your computer and use it in GitHub Desktop.
data InfiniteList a = InfiniteList a (InfiniteList a)
traverseForever :: Applicative m => (a -> m b) -> InfiniteList a -> m c
traverseForever f (InfiniteList x xs) = f x *> traverseForever f xs
countUpwardsFrom :: Integer -> InfiniteList Integer
countUpwardsFrom n = InfiniteList n (countUpwardsFrom (n + 1))
forForever :: Applicative m => InfiniteList a -> (a -> m b) -> m c
forForever = flip traverseForever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment