,我有以下CPS實施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)
哪種類型的檢查OK!現在,試圖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''在遞歸調用。 – chi
@chi;解決了謝謝 – cybertextron
你不應該編輯你的問題的答案 - 我一開始都感到困惑,因爲你的第一個版本現在可以工作...... –