7
我試圖總結我的周圍連拍和callCC頭:均分推理,通過減少該功能綁結
s0 = (flip runContT) return $ do
(k, n) <- callCC $ \k -> let f x = k (f, x)
in return (f, 0)
lift $ print n
if n < 3
then k (n+1) >> return()
else return()
我已經成功地實現了這一點:
s21 = runContT (let f x = ContT $ \_ -> cc (f, x) in ContT ($(f,0))) cc where
cc = (\(k,n) -> let
iff = if n < 3 then k (n+1) else ContT ($())
in print n >> runContT iff (\_ -> return()))
在這一點上,我不知道如何處理遞歸定義f
完成這種減少的最佳方法是什麼?
我現在離開定義'f',並開始展開'runContT'。只有在必須時才展開'f'。順便說一下,我發現'(k,n)<-...'中的名字'k'很混亂,因爲它看起來好像和'\ k - > ...一樣',但是這些甚至沒有相同的類型(一個是整數,另一個是一對)。 – chi
@chi這是一個來自[這裏](https://www.schoolofhaskell.com/user/jwiegley/understanding-continuations)的稍微改變的例子,但是其中的一個至少可以稱爲'k'' – Ryba