3 ms·
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> fac
by harpocrates 10y ago
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 http://stackoverflow.com/a/5885270/3072788
[2] http://stackoverflow.com/a/13119751/3072788 http://stackoverflow.com/a/13119751/3072788