Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有一种方法可以使用以下函数在 Haskell 中创建函数来计算阶乘:
fix f = f (fix f)
要原创
fac = (fix ((1:) . zipWith (*) [1..]) !!)
是的。琐碎的方法:
factorial = fix go 1 where go f acc n = fact acc n
哪里fact acc n === acc * n!。当然,这是一个完全荒谬的定义。
fact acc n === acc * n!
您能看到如何修改荒谬的定义以使其使用f参数吗?希望这将模仿您已经编写的显式递归定义的结构。
f