Skip to content

Instantly share code, notes, and snippets.

@thealmarty
Created January 24, 2019 23:34
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/6202b838e39733fd53de16e16338ef85 to your computer and use it in GitHub Desktop.
Save thealmarty/6202b838e39733fd53de16e16338ef85 to your computer and use it in GitHub Desktop.
The factoria function using hylomorphism in Haskell.
import Data.List --To enable unfoldr.
fact n =
foldr
(*) --Function input
1 --Base case
(unfoldr --List input
(\n -> if n==0 then Nothing else Just (n, n-1))
n)
--Print out example results of the fact fn.
main = do
print (fact 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment