小编wud*_*eng的帖子

cps在"又一个haskell turorial"中

我正在通过阅读"又一个Haskell教程"这本书来学习haskell,而且当谈到contiuation传递风格时我遇到了一个问题.这本书给出了一个cps折叠:

cfold’ f z [] = z
cfold’ f z (x:xs) = f x z (\y -> cfold’ f y xs)
Run Code Online (Sandbox Code Playgroud)

并给出测试结果:

CPS> cfold (+) 0 [1,2,3,4]
10
CPS> cfold (:) [] [1,2,3]
[1,2,3]
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试测试时,我发现存在问题,ghci给出:

*Main> cfold (+) 0 []

<interactive>:8:7:
    Occurs check: cannot construct the infinite type:
      t10 = (t10 -> t10) -> t10
    Expected type: t10 -> t10 -> (t10 -> t10) -> t10
      Actual type: t10 -> t10 -> t10
    In the first argument of `cfold', namely …
Run Code Online (Sandbox Code Playgroud)

haskell

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

标签 统计

haskell ×1