ghci> let xxs=[[1,3,5,2,3,1,2,4,5],[1,2,3,4,5,6,7,8,9],[1,2,4,2,1,6,3,1,3,2,3,6]]
ghci> [[x|x<- xs,even x]|xs<- xxs]
[[2,2,4],[2,4,6,8],[2,4,2,6,2,6]]
Run Code Online (Sandbox Code Playgroud)
这段代码与列表理解有关。但是我看不到程序如何与“偶数”一起使用
Filter :: (Ord a) => [a] -> [a]
Filter [X:XS] = [[c|c<X, c<-XS ] ++ [X] ++ [c| c >X , c<-XS ]]
quickSort :: Ord a => [a] -> [a]
quickSort [] = []
quickSort [x:xs] = quickSort mini ++ [x] + quickSort maxi
where
mini = filter xs
maxi = filter xs
Run Code Online (Sandbox Code Playgroud)
具有列表理解功能的“过滤器”功能正确吗?我知道Haskell-Libraries中有一个内置函数“ Filter”。但是我试图自己编写代码...