Skip to content

Instantly share code, notes, and snippets.

@thealmarty
Last active December 13, 2018 17: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 thealmarty/c70c020e5b41e28ca5e37e66d49a1482 to your computer and use it in GitHub Desktop.
Save thealmarty/c70c020e5b41e28ca5e37e66d49a1482 to your computer and use it in GitHub Desktop.
Anamorphisms example in Haskell
--Import Data.List so that we can use the unfoldr function.
import Data.List
--p and g are combined into one function which you input to unfoldr in Haskell:
example = unfoldr (\x -> if x > 9 then Nothing else Just (x, x+1))
--Print out results of (example 7) and (example 0).
main = do
print (example 7)
print (example 0)
@thealmarty
Copy link
Author

See my blog post for further explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment