Skip to content

Instantly share code, notes, and snippets.

@Javran
Created January 12, 2013 09:38
Show Gist options
  • Save Javran/4516960 to your computer and use it in GitHub Desktop.
Save Javran/4516960 to your computer and use it in GitHub Desktop.
Y combinator in haskell
-- plz refer to http://stackoverflow.com/questions/4273413/y-combinator-in-haskell
newtype Mu a = Mu (Mu a -> a)
y f = (\h -> h $ Mu h) (\x -> f. (\(Mu g) -> g) x $ x)
fakePower self n = if n == 0
then 1
else n*self(n-1)
truePower = y fakePower
main = putStr $ show $ truePower 10
-- output is '3628800'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment