@@ -171,11 +171,11 @@ not.
171 partition isEven [0..5] == ([0,2,4], [1,3,5])
171 partition isEven [0..5] == ([0,2,4], [1,3,5])
173partition : (a -> Bool) -> [a] -> ([a],[a])
173partition : (a -> Bool) -> [a] -> ([a],[a])
174−partition pred lst =
174+partition pred =
175− case lst of
175+ let step x (ts, fs) = if pred x
176− [] -> ([],[])
176+ then (x::ts, fs)
177− x::xs -> let (bs,cs) = partition pred xs in
177+ else (ts, x::fs)
178− if pred x then (x::bs,cs) else (bs,x::cs)
178+ in foldr step ([],[])
180{-| Combine two lists, combining them into tuples pairwise.
180{-| Combine two lists, combining them into tuples pairwise.
181If one list is longer, the extra elements are dropped.
181If one list is longer, the extra elements are dropped.
@@ -194,12 +194,13 @@ If one list is longer, the extra elements are dropped.
194zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
194zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
195zipWith = Native.List.zipWith
195zipWith = Native.List.zipWith
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])
198unzip : [(a,b)] -> ([a],[b])
200unzip : [(a,b)] -> ([a],[b])
199−unzip pairs =
201+unzip =
200− case pairs of
202+ let step (x,y) (xs, ys) = (x::xs, y::ys)
201− [] -> ([],[])
203+ in foldr step ([], [])
202− (x,y)::ps -> let (xs,ys) = (unzip ps) in (x::xs,y::ys)
204{-| Places the given value between all of the lists in the second
205{-| Places the given value between all of the lists in the second
205argument and concatenates the result.
206argument and concatenates the result.
@@ -215,10 +216,12 @@ join = Native.List.join
216intersperse : a -> [a] -> [a]
217intersperse : a -> [a] -> [a]
217intersperse sep xs =
218intersperse sep xs =
218− case xs of
219+ case xs of
219− a::b::cs -> a :: sep :: intersperse sep (b::cs)
220+ [] -> []
220− [a] -> [a]
221+ hd::tl ->
221− [] -> []
222+ let step x rest = sep :: x :: rest
223+ spersed = foldr step [] tl
223{-| Take the first n members of a list: `(take 2 [1,2,3,4] == [1,2])` -}
226{-| Take the first n members of a list: `(take 2 [1,2,3,4] == [1,2])` -}
224take : Int -> [a] -> [a]
227take : Int -> [a] -> [a]