2012-10-05 02:01:20 +00:00
|
|
|
|
2013-02-09 06:17:39 +00:00
|
|
|
module List where
|
2012-10-05 02:01:20 +00:00
|
|
|
|
2013-02-22 23:19:40 +00:00
|
|
|
import Native.List
|
2012-10-05 02:01:20 +00:00
|
|
|
|
2013-02-09 06:17:39 +00:00
|
|
|
head : [a] -> a
|
2013-02-22 23:19:40 +00:00
|
|
|
head = Native.List.head
|
2012-10-05 02:01:20 +00:00
|
|
|
|
2013-02-09 06:17:39 +00:00
|
|
|
tail : [a] -> [a]
|
2013-02-22 23:19:40 +00:00
|
|
|
tail = Native.List.tail
|
2012-10-05 02:01:20 +00:00
|
|
|
|
2013-02-10 09:45:45 +00:00
|
|
|
last : [a] -> a
|
2013-02-22 23:19:40 +00:00
|
|
|
last = Native.List.last
|
2013-02-10 09:45:45 +00:00
|
|
|
|
2013-02-09 06:17:39 +00:00
|
|
|
map : (a -> b) -> [a] -> [b]
|
2013-02-22 23:19:40 +00:00
|
|
|
map = Native.List.map
|
2013-02-09 06:17:39 +00:00
|
|
|
|
|
|
|
foldl : (a -> b -> b) -> b -> [a] -> b
|
2013-02-22 23:19:40 +00:00
|
|
|
foldl = Native.List.foldl
|
2013-02-09 06:17:39 +00:00
|
|
|
|
|
|
|
foldr : (a -> b -> b) -> b -> [a] -> b
|
2013-02-22 23:19:40 +00:00
|
|
|
foldr = Native.List.foldr
|
2013-02-09 06:17:39 +00:00
|
|
|
|
|
|
|
foldl1 : (a -> a -> a) -> [a] -> a
|
2013-02-22 23:19:40 +00:00
|
|
|
foldl1 = Native.List.foldl1
|
2013-02-09 06:17:39 +00:00
|
|
|
|
|
|
|
foldr1 : (a -> a -> a) -> [a] -> a
|
2013-02-22 23:19:40 +00:00
|
|
|
foldr1 = Native.List.foldr1
|
2013-02-09 06:17:39 +00:00
|
|
|
|
2013-02-10 04:36:57 +00:00
|
|
|
scanl : (a -> b -> b) -> b -> [a] -> [b]
|
2013-02-22 23:19:40 +00:00
|
|
|
scanl = Native.List.scanl
|
2013-02-10 04:36:57 +00:00
|
|
|
|
|
|
|
scanl1 : (a -> a -> a) -> [a] -> [a]
|
2013-02-22 23:19:40 +00:00
|
|
|
scanl1 = Native.List.scanl1
|
2012-10-05 02:01:20 +00:00
|
|
|
|
2013-02-09 06:17:39 +00:00
|
|
|
filter : (a -> Bool) -> [a] -> [a]
|
2013-02-22 23:19:40 +00:00
|
|
|
filter = Native.List.filter
|
2013-02-09 06:17:39 +00:00
|
|
|
|
|
|
|
length : [a] -> Int
|
2013-02-22 23:19:40 +00:00
|
|
|
length = Native.List.length
|
2013-02-09 06:17:39 +00:00
|
|
|
|
|
|
|
reverse : [a] -> [a]
|
2013-02-22 23:19:40 +00:00
|
|
|
reverse = Native.List.reverse
|
2012-10-05 02:01:20 +00:00
|
|
|
|
2013-02-10 09:45:45 +00:00
|
|
|
concat : [[a]] -> [a]
|
2013-02-22 23:19:40 +00:00
|
|
|
concat = Native.List.foldr (++) []
|
2012-10-05 02:01:20 +00:00
|
|
|
|
2013-02-10 09:45:45 +00:00
|
|
|
concatMap : (a -> [b]) -> [a] -> [b]
|
2013-02-22 23:19:40 +00:00
|
|
|
concatMap f = concat . Native.List.map f
|
2013-02-09 06:17:39 +00:00
|
|
|
|
2013-02-10 09:45:45 +00:00
|
|
|
all : (a -> Bool) -> [a] -> Bool
|
2013-02-22 23:19:40 +00:00
|
|
|
all pred = Native.List.all
|
2012-10-05 02:01:20 +00:00
|
|
|
|
2013-02-09 06:17:39 +00:00
|
|
|
any : (a -> Bool) -> [a] -> Bool
|
2013-02-22 23:19:40 +00:00
|
|
|
any = Native.List.any
|
2013-02-09 06:17:39 +00:00
|
|
|
|
2013-02-10 09:45:45 +00:00
|
|
|
and : [Bool] -> Bool
|
2013-02-22 23:19:40 +00:00
|
|
|
and = Native.List.all id
|
2013-02-10 09:45:45 +00:00
|
|
|
|
|
|
|
or : [Bool] -> Bool
|
2013-02-22 23:19:40 +00:00
|
|
|
or = Native.List.any id
|
2012-10-05 02:01:20 +00:00
|
|
|
|
|
|
|
sum = foldl (+) 0
|
|
|
|
product = foldl (*) 1
|
|
|
|
maximum = foldl1 max
|
|
|
|
minimum = foldl1 min
|
|
|
|
|
2013-02-09 06:17:39 +00:00
|
|
|
partition : (a -> Bool) -> [a] -> ([a],[a])
|
2012-10-05 02:01:20 +00:00
|
|
|
partition pred lst =
|
|
|
|
case lst of
|
2013-02-09 06:17:39 +00:00
|
|
|
[] -> ([],[])
|
|
|
|
x::xs -> let (as,bs) = partition pred xs in
|
|
|
|
if pred x then (x::as,bs) else (as,x::bs)
|
2012-10-05 02:01:20 +00:00
|
|
|
|
2013-02-09 06:17:39 +00:00
|
|
|
zipWith : (a -> b -> c) -> [a] -> [b] -> [c]
|
2013-02-22 23:19:40 +00:00
|
|
|
zipWith = Native.List.zipWith
|
2012-10-05 02:01:20 +00:00
|
|
|
|
2013-02-09 06:17:39 +00:00
|
|
|
zip : [a] -> [b] -> [(a,b)]
|
2013-02-22 23:19:40 +00:00
|
|
|
zip = Native.List.zip
|
2012-10-05 02:01:20 +00:00
|
|
|
|
2013-02-09 06:17:39 +00:00
|
|
|
unzip : [(a,b)] -> ([a],[b])
|
2012-10-05 02:01:20 +00:00
|
|
|
unzip pairs =
|
|
|
|
case pairs of
|
2013-02-09 06:17:39 +00:00
|
|
|
[] -> ([],[])
|
|
|
|
(x,y)::ps -> let (xs,ys) = (unzip ps) in (x::xs,y::ys)
|
2012-10-05 02:01:20 +00:00
|
|
|
|
|
|
|
intersperse sep xs =
|
2013-02-09 06:17:39 +00:00
|
|
|
case xs of
|
|
|
|
a::b::cs -> a :: sep :: intersperse sep (b::cs)
|
|
|
|
[a] -> [a]
|
|
|
|
[] -> []
|
|
|
|
|
2012-10-05 02:01:20 +00:00
|
|
|
intercalate sep xs =
|
2013-02-09 06:17:39 +00:00
|
|
|
case xs of
|
|
|
|
a::b::cs -> a ++ sep ++ intercalate sep (b::cs)
|
|
|
|
[a] -> a
|
|
|
|
[] -> []
|