【发布时间】:2016-01-24 03:58:39
【问题描述】:
我有以下until 的 CPS 实现:
until' p f x cc = p x (\y -> if y then cc(x)
else until' p f (f x (\z -> cc(z))) cc)
哪种类型检查正常!现在,尝试 CPS map:
map' f (x:xs) cc = f x (\y -> map f xs (\ys -> cc(y:ys)))
另一种可能的实现方式:
map' f (x:xs) cc = cc(f x (\y cc' -> map f xs (\ys -> cc'(y:ys))))
但是它们都没有类型检查。我在哪里做错了?
Couldn't match expected type ‘([a1] -> t2) -> t1’
with actual type ‘[(a1 -> t1) -> t]’
Relevant bindings include
y :: a1 (bound at test.hs:6:26)
cc :: [a1] -> t2 (bound at test.hs:6:15)
f :: a -> (a1 -> t1) -> t (bound at test.hs:6:6)
map' :: (a -> (a1 -> t1) -> t) -> [a] -> ([a1] -> t2) -> t
(bound at test.hs:6:1)
The function ‘map’ is applied to three arguments,
but its type ‘(a -> (a1 -> t1) -> t) -> [a] -> [(a1 -> t1) -> t]’
has only two
In the expression: map f xs (\ ys -> cc (y : ys))
In the second argument of ‘f’, namely
‘(\ y -> map f xs (\ ys -> cc (y : ys)))’
Failed, modules loaded: none.
【问题讨论】:
-
你在递归调用中调用
map而不是map'。 -
您不应该将答案编辑到您的问题中 - 一开始我很困惑,因为您的第一个版本现在可以使用...
标签: haskell continuations