我有以下Haskell方法
unfold :: (a -> Bool) -> (a -> b) -> (a -> a) -> a -> [b]
unfold p h t x
| p x = []
| otherwise = (h x):(unfold p h t (t x))
如何使用此给定的展开方法定义常规前奏图f x方法。
答案 0 :(得分:4)
如果你定义:
map' :: (a -> b) -> [a] -> [b]
map' f = unfold null (f.head) tail
然后
\> map' show [1..5]
["1","2","3","4","5"]
\> map' (+1) []
[]