mystery
做了什么?
mystery xs = foldr f [] xs
f next soFar = soFar ++ [next]
感谢。
答案 0 :(得分:1)
不,foldr f [] xs =/= []
。我们来看看,
mystery xs
= foldr f [] xs
-- ( assuming xs == (x:t), i.e. non-empty: )
= foldr f [] (x:t)
-- ( by definition of `foldr`: )
= f x (foldr f [] t)
-- ( by definition of `mystery`: )
= f x (mystery t)
= mystery t ++ [x]
那么,mystery
做了什么?例如,它对列表[a,b,c]
有什么作用?
mystery [a,b,c]
= mystery [b,c] ++ [a]
= (mystery [c] ++ [b]) ++ [a]
= ((mystery [] ++ [c]) ++ [b]) ++ [a]
= ...
你可以在这里完成图片。