小编Lea*_*ket的帖子

Haskell:在Continuation Passing Style中完全定义阶乘的问题

我一直试图在一个大blob中强调功能编程,Haskell和Continuation Passing Style,而我的结构化/ OOP背景让我很难过.

根据这一点,我理解以下应该是CPS风格的阶乘的正确定义:

factorial n = fact n id where id = \x -> x
    fact 0 cont = cont n
    fact (n+1) cont = fact n * (n + 1)
Run Code Online (Sandbox Code Playgroud)

但我不确定最后的"*(n + 1)"部分 - 这是正确的吗?

continuations haskell factorial

2
推荐指数
1
解决办法
1185
查看次数

标签 统计

continuations ×1

factorial ×1

haskell ×1