@@ -1,59 +1,88 @@
2−head (h:t) = h
2+module List where
5−map f lst = case lst of { x:xs -> f x : map f xs; [] -> [] }
4+import Native.List as Native
6−foldl f b lst = case lst of { x:xs -> foldl f (f x b) xs; [] -> b }
7−foldr f b lst = case lst of { x:xs -> f x (foldr f b xs); [] -> b }
9−foldl1 f (x:xs) = foldl f x xs
6+head : [a] -> a
10−foldr1 f (x:xs) = foldr f x xs
7+head = Native.head
12−scanl f b xs = b : (case xs of { x:xs -> scanl f (f x b) xs; [] -> [] })
9+tail : [a] -> [a]
13−scanl1 f lst = case lst of { x:xs -> scanl f x xs; [] -> [] }
10+tail = Native.tail
15−filter pred lst =
12+map : (a -> b) -> [a] -> [b]
16− case lst of
13+map = Native.map
17− { x:xs -> if pred x then x : filter pred xs else filter pred xs
14+
18− ; [] -> [] }
15+foldl : (a -> b -> b) -> b -> [a] -> b
18+foldr : (a -> b -> b) -> b -> [a] -> b
21+foldl1 : (a -> a -> a) -> [a] -> a
22+foldl1 f (x::xs) = foldl f x xs
24+foldr1 : (a -> a -> a) -> [a] -> a
25+foldr1 f (x::xs) = foldr f x xs
27+scanl f b xs = b :: (case xs of { x::xs -> scanl f (f x b) xs; [] -> [] })
28+scanl1 f lst = case lst of { x::xs -> scanl f x xs; [] -> [] }
20−length = foldl (\x c -> 1 + c) 0
30+filter : (a -> Bool) -> [a] -> [a]
31+filter = Native.filter
34+length = Native.length
21−reverse = foldl (:) []
37+reverse = foldl (::) []
23concat = foldr (++) []
39concat = foldr (++) []
24concatMap f = concat . map f
40concatMap f = concat . map f
26and = foldl (&&) True
43and = foldl (&&) True
27or = foldl (||) False
46or = foldl (||) False
48+any : (a -> Bool) -> [a] -> Bool
29−forall pred = foldl (\x acc -> acc && pred x) True
49+any pred = foldl (\x acc -> acc && pred x) True
51+all : (a -> Bool) -> [a] -> Bool
30−exists pred = foldl (\x acc -> acc || pred x) False
52+all pred = foldl (\x acc -> acc || pred x) False
32sum = foldl (+) 0
54sum = foldl (+) 0
33product = foldl (*) 1
55product = foldl (*) 1
34maximum = foldl1 max
56maximum = foldl1 max
35minimum = foldl1 min
57minimum = foldl1 min
59+partition : (a -> Bool) -> [a] -> ([a],[a])
37partition pred lst =
60partition pred lst =
38 case lst of
61 case lst of
39− { x:xs -> case partition pred xs of
63+ x::xs -> let (as,bs) = partition pred xs in
40− { (as,bs) -> if pred x then (x:as,bs) else (as,x:bs) }
64+ if pred x then (x::as,bs) else (as,x::bs)
43−zipWith f listA listB = case (listA, listB) of
66+zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
44− { (a:as, b:bs) -> f a b : zipWith f as bs; _ -> [] }
67+zipWith = Native.zipWith
46−zip listA listB = case (listA, listB) of
69+zip : [a] -> [b] -> [(a,b)]
47− { (a:as, b:bs) -> (a,b) : zip as bs; _ -> [] }
70+zip = Native.zip
72+unzip : [(a,b)] -> ([a],[b])
49unzip pairs =
73unzip pairs =
50 case pairs of
74 case pairs of
51− { p:ps -> case (p, unzip ps) of { ((x,y),(xs,ys)) -> (x:xs,y:ys) }
75+ [] -> ([],[])
52− ; [] -> ([],[]) }
76+ (x,y)::ps -> let (xs,ys) = (unzip ps) in (x::xs,y::ys)
54intersperse sep xs =
78intersperse sep xs =
55− case xs of { a:b:cs -> a : sep : intersperse sep (b:cs)
80+ a::b::cs -> a :: sep :: intersperse sep (b::cs)
56− ; a:[] -> [a] ; [] -> [] }
81+ [a] -> [a]
57intercalate sep xs =
84intercalate sep xs =
58− case xs of { a:b:cs -> a ++ sep ++ intercalate sep (b:cs)
86+ a::b::cs -> a ++ sep ++ intercalate sep (b::cs)
59− ; a:[] -> a ; [] -> [] }
87+ [a] -> a