@@ -170,13 +170,12 @@ not.
170 partition (\x -> x < 3) [0..5] == ([0,1,2], [3,4,5])
170 partition (\x -> x < 3) [0..5] == ([0,1,2], [3,4,5])
171 partition isEven [0..5] == ([0,2,4], [1,3,5])
171 partition isEven [0..5] == ([0,2,4], [1,3,5])
174partition : (a -> Bool) -> [a] -> ([a],[a])
173partition : (a -> Bool) -> [a] -> ([a],[a])
175−partition pred lst =
174+partition pred =
176− case lst of
175+ let step x (ts, fs) = if pred x
177− [] -> ([],[])
176+ then (x::ts, fs)
178− x::xs -> let (bs,cs) = partition pred xs in
177+ else (ts, x::fs)
179− if pred x then (x::bs,cs) else (bs,x::cs)
178+ in foldr step ([],[])
181{-| Combine two lists, combining them into tuples pairwise.
180{-| Combine two lists, combining them into tuples pairwise.
182If one list is longer, the extra elements are dropped.
181If one list is longer, the extra elements are dropped.
@@ -198,12 +197,10 @@ zipWith = Native.List.zipWith
198{-| Decompose a list of tuples.
197{-| Decompose a list of tuples.
199 unzip [(0, True), (17, False), (1337, True)] == ([0,17,1337], [True,False,True])
198 unzip [(0, True), (17, False), (1337, True)] == ([0,17,1337], [True,False,True])
202unzip : [(a,b)] -> ([a],[b])
200unzip : [(a,b)] -> ([a],[b])
203−unzip pairs =
201+unzip =
204− case pairs of
202+ let step (x,y) (xs, ys) = (x::xs, y::ys)
205− [] -> ([],[])
203+ in foldr step ([], [])
206− (x,y)::ps -> let (xs,ys) = (unzip ps) in (x::xs,y::ys)
208{-| 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
209argument and concatenates the result.
206argument and concatenates the result.
@@ -217,13 +214,14 @@ join = Native.List.join
218 intersperse "on" ["turtles","turtles","turtles"] == ["turtles","on","turtles","on","turtles"]
215 intersperse "on" ["turtles","turtles","turtles"] == ["turtles","on","turtles","on","turtles"]
221intersperse : a -> [a] -> [a]
217intersperse : a -> [a] -> [a]
222intersperse sep xs =
218intersperse sep xs =
223− case xs of
219+ case xs of
224− a::b::cs -> a :: sep :: intersperse sep (b::cs)
220+ [] -> []
225− [a] -> [a]
221+ hd::tl ->
226− [] -> []
222+ let step x rest = sep :: x :: rest
223+ spersed = foldr step [] tl
228{-| 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])` -}
229take : Int -> [a] -> [a]
227take : Int -> [a] -> [a]