News for hackers. Stuff that matters.
Re:Ask HN: What is your favorite equation? by harpocrates on Saturday December 24, 2016 @03:27AM (#13249096)
This works in Haskell just fine, thank you very much!

    ghci> y f = f (y f)
    ghci> factorial = y (\f x -> if x == 0 then 1 else x * f (x-1))
    ghci> factorial 5
    120
However, the Y combinator as defined in a non-recursive form is tougher to implement in Haskell [1][2]. It looks a lot better in Racket (and this is coming from someone who doesn't particularly like Racket).

    (λ (r) (λ (h) (h h)) (λ (g) (r (λ (x) (g g) x))
[1] http://stackoverflow.com/a/5885270/3072788 [2] http://stackoverflow.com/a/13119751/3072788

There are no comments on this comment yet.