Skip to content

Instantly share code, notes, and snippets.

@Xodarap
Created May 25, 2011 01:04
Show Gist options
  • Save Xodarap/990116 to your computer and use it in GitHub Desktop.
Save Xodarap/990116 to your computer and use it in GitHub Desktop.
Fake YC application
-- | 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