我一直试图在一个大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)"部分 - 这是正确的吗?