Created
May 25, 2011 01:04
-
-
Save Xodarap/990116 to your computer and use it in GitHub Desktop.
Fake YC application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | Mu is just a wrapper since we can't create infinitely recursive type | |
-- signatures for functions, but we can create recursive ADTs. | |
-- You can glean the point of Mu from the type signature of actualFn | |
data Mu a = Mu { actualFn :: [Mu a] -> a -> a } | |
-- | Factorial function | |
fact :: Num a => [Mu a] -- ^ An infinite list of factorial functions | |
-> a -- ^ The number to find the factorial of | |
-> a | |
fact (f:fs) n = if n == 1 then 1 | |
else n * ((actualFn f) fs (n-1)) | |
-- | Create an infinite list, each element is a factorial function | |
-- wrapped in a Mu | |
genFact :: Num a => [Mu a] | |
genFact = (Mu fact):genFact |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment