drkcore

2009/12/01 21:49:57

foldrでfilter

RWHのp.99

右から畳み込むはずなのに、、、不思議な感じがする。

myfilter p xs = foldr step [] xs
                where step x ys | p x = x:ys
                                | otherwise = ys

myfilter odd [1,2,3,4,5,6]
[1,3,5]

結局これは

(1:(3:(5:[])))

を評価してんのか。

ProductName Real World Haskell―実戦で学ぶ関数型言語プログラミング
Bryan O'Sullivan,John Goerzen,Don Stewart
オライリージャパン / ¥ 3,990 ()
在庫あり。

Comments