Is there is a way to create function to calculate factorial in Haskell, using the following function:
fix f = f (fix f)
Is there is a way to create function to calculate factorial in Haskell, using the following function:
fix f = f (fix f)
Yes. The trivial way:
factorial = fix go 1 where
go f acc n = fact acc n
Where fact acc n === acc * n!
. This is, of course, an altogether ridiculous definition.
Can you see how to modify the ridiculous definition so that it uses the f
parameter? This will, hopefully, mimic the structure of the explicitly recursive definition you've already written.