@@ -171,11 +171,11 @@ not.
171171 partition isEven [0..5] == ([0,2,4], [1,3,5])
172172-}
173173partition : (a -> Bool) -> [a] -> ([a],[a])
174−partition pred lst =
175− case lst of
176− [] -> ([],[])
177− x::xs -> let (bs,cs) = partition pred xs in
178− if pred x then (x::bs,cs) else (bs,x::cs)
174+partition pred =
175+ let step x (ts, fs) = if pred x
176+ then (x::ts, fs)
177+ else (ts, x::fs)
178+ in foldr step ([],[])
179179
180180{-| Combine two lists, combining them into tuples pairwise.
181181If one list is longer, the extra elements are dropped.
@@ -194,12 +194,13 @@ If one list is longer, the extra elements are dropped.
194194zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
195195zipWith = Native.List.zipWith
196196
197−{-| Decompose a list of tuples. -}
197+{-| Decompose a list of tuples.
198+ unzip [(0, True), (17, False), (1337, True)] == ([0,17,1337], [True,False,True])
199+-}
198200unzip : [(a,b)] -> ([a],[b])
199−unzip pairs =
200− case pairs of
201− [] -> ([],[])
202− (x,y)::ps -> let (xs,ys) = (unzip ps) in (x::xs,y::ys)
201+unzip =
202+ let step (x,y) (xs, ys) = (x::xs, y::ys)
203+ in foldr step ([], [])
203204
204205{-| Places the given value between all of the lists in the second
205206argument and concatenates the result.
@@ -215,10 +216,12 @@ join = Native.List.join
215216-}
216217intersperse : a -> [a] -> [a]
217218intersperse sep xs =
218− case xs of
219− a::b::cs -> a :: sep :: intersperse sep (b::cs)
220− [a] -> [a]
221− [] -> []
219+ case xs of
220+ [] -> []
221+ hd::tl ->
222+ let step x rest = sep :: x :: rest
223+ spersed = foldr step [] tl
224+ in hd :: spersed
222225
223226{-| Take the first n members of a list: `(take 2 [1,2,3,4] == [1,2])` -}
224227take : Int -> [a] -> [a]