@@ -3,6 +3,7 @@ module Prelude.List
33import Builtins
44
55import Prelude.Algebra
6+import Prelude.Foldable
67import Prelude.Functor
78import Prelude.Maybe
89import Prelude.Nat
@@ -217,41 +218,18 @@ mapMaybe f (x::xs) =
217218-- Folds
218219--------------------------------------------------------------------------------
219220
220−foldl : (a -> b -> a) -> a -> List b -> a
221−foldl f e [] = e
222−foldl f e (x::xs) = foldl f (f e x) xs
223−
224−foldr : (a -> b -> b) -> b -> List a -> b
225−foldr f e [] = e
226−foldr f e (x::xs) = f x (foldr f e xs)
221+instance Foldable List where
222+ foldr f e [] = e
223+ foldr f e (x::xs) = f x (foldr f e xs)
227224
228225--------------------------------------------------------------------------------
229226-- Special folds
230227--------------------------------------------------------------------------------
231228
232−mconcat : Monoid a => List a -> a
233−mconcat = foldr (<+>) neutral
234−
235−concat : List (List a) -> List a
236−concat [] = []
237−concat (x::xs) = x ++ concat xs
238−
239229concatMap : (a -> List b) -> List a -> List b
240230concatMap f [] = []
241231concatMap f (x::xs) = f x ++ concatMap f xs
242232
243−and : List Bool -> Bool
244−and = foldr (&&) True
245−
246−or : List Bool -> Bool
247−or = foldr (||) False
248−
249−any : (a -> Bool) -> List a -> Bool
250−any p = or . map p
251−
252−all : (a -> Bool) -> List a -> Bool
253−all p = and . map p
254−
255233--------------------------------------------------------------------------------
256234-- Transformations
257235--------------------------------------------------------------------------------