-8

Is there is a way to create function to calculate factorial in Haskell, using the following function:

fix f = f (fix f)
duplode
  • 31,361
  • 7
  • 69
  • 130
Jack
  • 9

2 Answers2

4

To be original

fac = (fix ((1:) . zipWith (*) [1..]) !!)
user3237465
  • 12,116
  • 2
  • 15
  • 33
2

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.

dfeuer
  • 44,398
  • 3
  • 56
  • 155