Categories: Uncategorized

[Haskell]Least Fixed-Point

import Data.Function

factF f = \n -> if n == 0 then 1 else n * f(n-1)
fact0 = factF undefined
fact1 = factF . factF $ undefined
fact2 = factF . factF . factF $ undefined
fact3 = factF . factF . factF . factF $ undefined
fact = fix factF
$ghci
Prelude>:load fact.hs
*Main> fact0 0
1
*Main> fact0 1
*** Exception: Prelude.undefined
*Main> fact1 0
1
*Main> fact1 1
1
*Main> fact1 2
*** Exception: Prelude.undefined
*Main> fact 100
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
zuqqhi2