プログラミング Haskell 第7章 高階関数 練習問題その1
今日は 7.8 練習問題を解いてみます。
1.
((map f) . (filter p)) xs
2.
all _ [] = True all f (x:xs) = if f x == False then False else all f xs または all f xs = foldl (&&) True (map f xs) any _ [] = False any f (x:xs) = if f x == True then True else any f xs または all f xs = foldl (||) False (map f xs)
3.
map f = foldr (applyconcat f) [] where applyconcat f x xs = (f x) : xs filter p = foldr (selectconcat p) [] where selectconcat f x xs = if f x == True then (f x) : xs else xs
4.
これは foldl なら簡単なのですが
dectoint = foldl acum 0 where acum x y = x * 10 + y
foldr でどうやっていいのか思いつきません。
↑問題文の読み間違いで、foldl を用いてとありました。すぐ上の 3. の foldr を用いて、という文と見間違えたらしい。
今日はここまで。終わりませんでした。