标签:
①循环?NO!请递归思考问题!
手艹一个求列表中最大值代码,C语言中习惯性for扫一下比较出最大值。但是可以用递归!
maximum‘::(Ord a)=>[a]->a maximum‘ []=error "empty!" maximum‘ [x]=x maximum‘ (x:xs) = max x (maximum‘ xs)
同样的对列表的递归技巧可以手艹出take、reverse、repeat、zip
rev::[a]->[a] rev []=[] rev (x:xs)=rev xs++[x] //后端插入用++
zip‘::[a]->[b]->[(a,b)] zip‘ [] _=[] zip‘ _ []=[] zip‘ (x:xs) (y:ys)=[(x,y)]++zip‘ xs ys
标签:
原文地址:http://www.cnblogs.com/neopenx/p/4279580.html