我試圖按照foldr
的術語定義原始遞歸,如A tutorial on the universality and expressiveness on fold第4.1章所述。模式匹配與解構的嚴格性
這裏是它
simpleRecursive f v xs = fst $ foldr g (v,[]) xs
where
g x (acc, xs) = (f x xs acc,x:xs)
然而,以上定義不停止對head $ simpleRecursive (\x xs acc -> x:xs) [] [1..]
第一次嘗試下面是暫停
simpleRecursive f v xs = fst $ foldr g (v,[]) xs
where
g x r = let (acc,xs) = r
in (f x xs acc,x:xs)
鑑於幾乎相同的定義,但不同的結果定義,爲什麼它有所不同?這與Haskell模式如何匹配有關嗎?
可能與一個範圍問題與'xs',因爲它移動到的'g'解決問題的定義。 – chepner