{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE NoImplicitPrelude, ScopedTypeVariables,
MagicHash, BangPatterns #-}
module GHC.Internal.Data.OldList
(
(++)
, head
, last
, tail
, init
, uncons
, unsnoc
, singleton
, null
, length
, map
, reverse
, intersperse
, intercalate
, transpose
, subsequences
, permutations
, foldl
, foldl'
, foldl1
, foldl1'
, foldr
, foldr1
, concat
, concatMap
, and
, or
, any
, all
, sum
, product
, maximum
, minimum
, scanl
, scanl'
, scanl1
, scanr
, scanr1
, mapAccumL
, mapAccumR
, iterate
, iterate'
, repeat
, replicate
, cycle
, unfoldr
, take
, drop
, splitAt
, takeWhile
, dropWhile
, dropWhileEnd
, span
, break
, stripPrefix
, group
, inits
, tails
, isPrefixOf
, isSuffixOf
, isInfixOf
, elem
, notElem
, lookup
, find
, filter
, partition
, (!?)
, (!!)
, elemIndex
, elemIndices
, findIndex
, findIndices
, zip
, zip3
, zip4, zip5, zip6, zip7
, zipWith
, zipWith3
, zipWith4, zipWith5, zipWith6, zipWith7
, unzip
, unzip3
, unzip4, unzip5, unzip6, unzip7
, lines
, words
, unlines
, unwords
, nub
, delete
, (\\)
, union
, intersect
, sort
, sortOn
, insert
, nubBy
, deleteBy
, deleteFirstsBy
, unionBy
, intersectBy
, groupBy
, sortBy
, insertBy
, maximumBy
, minimumBy
, genericLength
, genericTake
, genericDrop
, genericSplitAt
, genericIndex
, genericReplicate
) where
import GHC.Internal.Data.Maybe
import GHC.Internal.Data.Bits ( (.&.) )
import GHC.Internal.Unicode ( isSpace )
import GHC.Internal.Data.Ord ( comparing )
import GHC.Internal.Data.Tuple ( fst, snd )
import GHC.Internal.Num
import GHC.Internal.Real
import GHC.Internal.List
import GHC.Internal.Base
infix 5 \\
dropWhileEnd :: (a -> Bool) -> [a] -> [a]
dropWhileEnd :: forall a. (a -> Bool) -> [a] -> [a]
dropWhileEnd a -> Bool
p = (a -> [a] -> [a]) -> [a] -> [a] -> [a]
forall a b. (a -> b -> b) -> b -> [a] -> b
foldr (\a
x [a]
xs -> if a -> Bool
p a
x Bool -> Bool -> Bool
&& [a] -> Bool
forall a. [a] -> Bool
null [a]
xs then [] else a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
xs) []
stripPrefix :: Eq a => [a] -> [a] -> Maybe [a]
stripPrefix :: forall a. Eq a => [a] -> [a] -> Maybe [a]
stripPrefix [] [a]
ys = [a] -> Maybe [a]
forall a. a -> Maybe a
Just [a]
ys
stripPrefix (a
x:[a]
xs) (a
y:[a]
ys)
| a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y = [a] -> [a] -> Maybe [a]
forall a. Eq a => [a] -> [a] -> Maybe [a]
stripPrefix [a]
xs [a]
ys
stripPrefix [a]
_ [a]
_ = Maybe [a]
forall a. Maybe a
Nothing
elemIndex :: Eq a => a -> [a] -> Maybe Int
elemIndex :: forall a. Eq a => a -> [a] -> Maybe Int
elemIndex a
x [a]
xs = (a -> Bool) -> [a] -> Maybe Int
forall a. (a -> Bool) -> [a] -> Maybe Int
findIndex (a
xa -> a -> Bool
forall a. Eq a => a -> a -> Bool
==) [a]
xs
elemIndices :: Eq a => a -> [a] -> [Int]
elemIndices :: forall a. Eq a => a -> [a] -> [Int]
elemIndices a
x [a]
xs = (a -> Bool) -> [a] -> [Int]
forall a. (a -> Bool) -> [a] -> [Int]
findIndices (a
xa -> a -> Bool
forall a. Eq a => a -> a -> Bool
==) [a]
xs
find :: (a -> Bool) -> [a] -> Maybe a
find :: forall a. (a -> Bool) -> [a] -> Maybe a
find a -> Bool
p = [a] -> Maybe a
forall a. [a] -> Maybe a
listToMaybe ([a] -> Maybe a) -> ([a] -> [a]) -> [a] -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
filter a -> Bool
p
findIndex :: (a -> Bool) -> [a] -> Maybe Int
findIndex :: forall a. (a -> Bool) -> [a] -> Maybe Int
findIndex a -> Bool
p = [Int] -> Maybe Int
forall a. [a] -> Maybe a
listToMaybe ([Int] -> Maybe Int) -> ([a] -> [Int]) -> [a] -> Maybe Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Bool) -> [a] -> [Int]
forall a. (a -> Bool) -> [a] -> [Int]
findIndices a -> Bool
p
findIndices :: (a -> Bool) -> [a] -> [Int]
{-# INLINABLE findIndices #-}
findIndices :: forall a. (a -> Bool) -> [a] -> [Int]
findIndices a -> Bool
p [a]
ls = (forall b. (Int -> b -> b) -> b -> b) -> [Int]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build ((forall b. (Int -> b -> b) -> b -> b) -> [Int])
-> (forall b. (Int -> b -> b) -> b -> b) -> [Int]
forall a b. (a -> b) -> a -> b
$ \Int -> b -> b
c b
n ->
let go :: a -> (Int# -> b) -> Int# -> b
go a
x Int# -> b
r Int#
k | a -> Bool
p a
x = Int# -> Int
I# Int#
k Int -> b -> b
`c` Int# -> b
r (Int#
k Int# -> Int# -> Int#
+# Int#
1#)
| Bool
otherwise = Int# -> b
r (Int#
k Int# -> Int# -> Int#
+# Int#
1#)
in (a -> (Int# -> b) -> Int# -> b) -> (Int# -> b) -> [a] -> Int# -> b
forall a b. (a -> b -> b) -> b -> [a] -> b
foldr a -> (Int# -> b) -> Int# -> b
go (\Int#
_ -> b
n) [a]
ls Int#
0#
isPrefixOf :: (Eq a) => [a] -> [a] -> Bool
isPrefixOf :: forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf [] [a]
_ = Bool
True
isPrefixOf [a]
_ [] = Bool
False
isPrefixOf (a
x:[a]
xs) (a
y:[a]
ys)= a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y Bool -> Bool -> Bool
&& [a] -> [a] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf [a]
xs [a]
ys
isSuffixOf :: (Eq a) => [a] -> [a] -> Bool
[a]
ns isSuffixOf :: forall a. Eq a => [a] -> [a] -> Bool
`isSuffixOf` [a]
hs = Bool -> (Bool -> Bool) -> Maybe Bool -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False Bool -> Bool
forall a. a -> a
id (Maybe Bool -> Bool) -> Maybe Bool -> Bool
forall a b. (a -> b) -> a -> b
$ do
delta <- [a] -> [a] -> Maybe [a]
forall a b. [a] -> [b] -> Maybe [b]
dropLengthMaybe [a]
ns [a]
hs
return $ ns == dropLength delta hs
dropLength :: [a] -> [b] -> [b]
dropLength :: forall a b. [a] -> [b] -> [b]
dropLength [] [b]
y = [b]
y
dropLength [a]
_ [] = []
dropLength (a
_:[a]
x') (b
_:[b]
y') = [a] -> [b] -> [b]
forall a b. [a] -> [b] -> [b]
dropLength [a]
x' [b]
y'
dropLengthMaybe :: [a] -> [b] -> Maybe [b]
dropLengthMaybe :: forall a b. [a] -> [b] -> Maybe [b]
dropLengthMaybe [] [b]
y = [b] -> Maybe [b]
forall a. a -> Maybe a
Just [b]
y
dropLengthMaybe [a]
_ [] = Maybe [b]
forall a. Maybe a
Nothing
dropLengthMaybe (a
_:[a]
x') (b
_:[b]
y') = [a] -> [b] -> Maybe [b]
forall a b. [a] -> [b] -> Maybe [b]
dropLengthMaybe [a]
x' [b]
y'
isInfixOf :: (Eq a) => [a] -> [a] -> Bool
isInfixOf :: forall a. Eq a => [a] -> [a] -> Bool
isInfixOf [a]
needle [a]
haystack = ([a] -> Bool) -> [[a]] -> Bool
forall a. (a -> Bool) -> [a] -> Bool
any ([a] -> [a] -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf [a]
needle) ([a] -> [[a]]
forall a. [a] -> [[a]]
tails [a]
haystack)
nub :: (Eq a) => [a] -> [a]
nub :: forall a. Eq a => [a] -> [a]
nub = (a -> a -> Bool) -> [a] -> [a]
forall a. (a -> a -> Bool) -> [a] -> [a]
nubBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
nubBy :: (a -> a -> Bool) -> [a] -> [a]
nubBy :: forall a. (a -> a -> Bool) -> [a] -> [a]
nubBy a -> a -> Bool
eq [a]
l = [a] -> [a] -> [a]
nubBy' [a]
l []
where
nubBy' :: [a] -> [a] -> [a]
nubBy' [] [a]
_ = []
nubBy' (a
y:[a]
ys) [a]
xs
| (a -> a -> Bool) -> a -> [a] -> Bool
forall a. (a -> a -> Bool) -> a -> [a] -> Bool
elem_by a -> a -> Bool
eq a
y [a]
xs = [a] -> [a] -> [a]
nubBy' [a]
ys [a]
xs
| Bool
otherwise = a
y a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a] -> [a]
nubBy' [a]
ys (a
ya -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
xs)
elem_by :: (a -> a -> Bool) -> a -> [a] -> Bool
elem_by :: forall a. (a -> a -> Bool) -> a -> [a] -> Bool
elem_by a -> a -> Bool
_ a
_ [] = Bool
False
elem_by a -> a -> Bool
eq a
y (a
x:[a]
xs) = a
x a -> a -> Bool
`eq` a
y Bool -> Bool -> Bool
|| (a -> a -> Bool) -> a -> [a] -> Bool
forall a. (a -> a -> Bool) -> a -> [a] -> Bool
elem_by a -> a -> Bool
eq a
y [a]
xs
delete :: (Eq a) => a -> [a] -> [a]
delete :: forall a. Eq a => a -> [a] -> [a]
delete = (a -> a -> Bool) -> a -> [a] -> [a]
forall a. (a -> a -> Bool) -> a -> [a] -> [a]
deleteBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]
deleteBy :: forall a. (a -> a -> Bool) -> a -> [a] -> [a]
deleteBy a -> a -> Bool
_ a
_ [] = []
deleteBy a -> a -> Bool
eq a
x (a
y:[a]
ys) = if a
x a -> a -> Bool
`eq` a
y then [a]
ys else a
y a -> [a] -> [a]
forall a. a -> [a] -> [a]
: (a -> a -> Bool) -> a -> [a] -> [a]
forall a. (a -> a -> Bool) -> a -> [a] -> [a]
deleteBy a -> a -> Bool
eq a
x [a]
ys
(\\) :: (Eq a) => [a] -> [a] -> [a]
\\ :: forall a. Eq a => [a] -> [a] -> [a]
(\\) = ([a] -> a -> [a]) -> [a] -> [a] -> [a]
forall a b. (b -> a -> b) -> b -> [a] -> b
foldl ((a -> [a] -> [a]) -> [a] -> a -> [a]
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> [a] -> [a]
forall a. Eq a => a -> [a] -> [a]
delete)
union :: (Eq a) => [a] -> [a] -> [a]
union :: forall a. Eq a => [a] -> [a] -> [a]
union = (a -> a -> Bool) -> [a] -> [a] -> [a]
forall a. (a -> a -> Bool) -> [a] -> [a] -> [a]
unionBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
unionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
unionBy :: forall a. (a -> a -> Bool) -> [a] -> [a] -> [a]
unionBy a -> a -> Bool
eq [a]
xs [a]
ys = [a]
xs [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ ([a] -> a -> [a]) -> [a] -> [a] -> [a]
forall a b. (b -> a -> b) -> b -> [a] -> b
foldl ((a -> [a] -> [a]) -> [a] -> a -> [a]
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> a -> Bool) -> a -> [a] -> [a]
forall a. (a -> a -> Bool) -> a -> [a] -> [a]
deleteBy a -> a -> Bool
eq)) ((a -> a -> Bool) -> [a] -> [a]
forall a. (a -> a -> Bool) -> [a] -> [a]
nubBy a -> a -> Bool
eq [a]
ys) [a]
xs
intersect :: (Eq a) => [a] -> [a] -> [a]
intersect :: forall a. Eq a => [a] -> [a] -> [a]
intersect = (a -> a -> Bool) -> [a] -> [a] -> [a]
forall a. (a -> a -> Bool) -> [a] -> [a] -> [a]
intersectBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
intersectBy :: forall a. (a -> a -> Bool) -> [a] -> [a] -> [a]
intersectBy a -> a -> Bool
_ [] [a]
_ = []
intersectBy a -> a -> Bool
_ [a]
_ [] = []
intersectBy a -> a -> Bool
eq [a]
xs [a]
ys = [a
x | a
x <- [a]
xs, (a -> Bool) -> [a] -> Bool
forall a. (a -> Bool) -> [a] -> Bool
any (a -> a -> Bool
eq a
x) [a]
ys]
intersperse :: a -> [a] -> [a]
intersperse :: forall a. a -> [a] -> [a]
intersperse a
_ [] = []
intersperse a
sep (a
x:[a]
xs) = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a -> [a] -> [a]
forall a. a -> [a] -> [a]
prependToAll a
sep [a]
xs
prependToAll :: a -> [a] -> [a]
prependToAll :: forall a. a -> [a] -> [a]
prependToAll a
_ [] = []
prependToAll a
sep (a
x:[a]
xs) = a
sep a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a -> [a] -> [a]
forall a. a -> [a] -> [a]
prependToAll a
sep [a]
xs
intercalate :: [a] -> [[a]] -> [a]
intercalate :: forall a. [a] -> [[a]] -> [a]
intercalate [a]
xs [[a]]
xss = [[a]] -> [a]
forall a. [[a]] -> [a]
concat ([a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
intersperse [a]
xs [[a]]
xss)
transpose :: [[a]] -> [[a]]
transpose :: forall a. [[a]] -> [[a]]
transpose [] = []
transpose ([] : [[a]]
xss) = [[a]] -> [[a]]
forall a. [[a]] -> [[a]]
transpose [[a]]
xss
transpose ((a
x : [a]
xs) : [[a]]
xss) = a -> [a] -> [a] -> [[a]] -> [[a]]
forall {a}. a -> [a] -> [a] -> [[a]] -> [[a]]
combine a
x [a]
hds [a]
xs [[a]]
tls
where
([a]
hds, [[a]]
tls) = [(a, [a])] -> ([a], [[a]])
forall a b. [(a, b)] -> ([a], [b])
unzip [(a
hd, [a]
tl) | a
hd : [a]
tl <- [[a]]
xss]
combine :: a -> [a] -> [a] -> [[a]] -> [[a]]
combine a
y [a]
h [a]
ys [[a]]
t = (a
ya -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
h) [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [[a]] -> [[a]]
forall a. [[a]] -> [[a]]
transpose ([a]
ys[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
:[[a]]
t)
{-# NOINLINE combine #-}
partition :: (a -> Bool) -> [a] -> ([a],[a])
{-# INLINE partition #-}
partition :: forall a. (a -> Bool) -> [a] -> ([a], [a])
partition a -> Bool
p [a]
xs = (a -> ([a], [a]) -> ([a], [a])) -> ([a], [a]) -> [a] -> ([a], [a])
forall a b. (a -> b -> b) -> b -> [a] -> b
foldr ((a -> Bool) -> a -> ([a], [a]) -> ([a], [a])
forall a. (a -> Bool) -> a -> ([a], [a]) -> ([a], [a])
select a -> Bool
p) ([],[]) [a]
xs
select :: (a -> Bool) -> a -> ([a], [a]) -> ([a], [a])
select :: forall a. (a -> Bool) -> a -> ([a], [a]) -> ([a], [a])
select a -> Bool
p a
x ~([a]
ts,[a]
fs) | a -> Bool
p a
x = (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
ts,[a]
fs)
| Bool
otherwise = ([a]
ts, a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
fs)
mapAccumL :: (acc -> x -> (acc, y))
-> acc
-> [x]
-> (acc, [y])
{-# NOINLINE [1] mapAccumL #-}
mapAccumL :: forall acc x y. (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
mapAccumL acc -> x -> (acc, y)
_ acc
s [] = (acc
s, [])
mapAccumL acc -> x -> (acc, y)
f acc
s (x
x:[x]
xs) = (acc
s'',y
yy -> [y] -> [y]
forall a. a -> [a] -> [a]
:[y]
ys)
where (acc
s', y
y ) = acc -> x -> (acc, y)
f acc
s x
x
(acc
s'',[y]
ys) = (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
forall acc x y. (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
mapAccumL acc -> x -> (acc, y)
f acc
s' [x]
xs
{-# RULES
"mapAccumL" [~1] forall f s xs . mapAccumL f s xs = foldr (mapAccumLF f) pairWithNil xs s
"mapAccumLList" [1] forall f s xs . foldr (mapAccumLF f) pairWithNil xs s = mapAccumL f s xs
#-}
pairWithNil :: acc -> (acc, [y])
{-# INLINE [0] pairWithNil #-}
pairWithNil :: forall acc y. acc -> (acc, [y])
pairWithNil acc
x = (acc
x, [])
mapAccumLF :: (acc -> x -> (acc, y)) -> x -> (acc -> (acc, [y])) -> acc -> (acc, [y])
{-# INLINE [0] mapAccumLF #-}
mapAccumLF :: forall acc x y.
(acc -> x -> (acc, y))
-> x -> (acc -> (acc, [y])) -> acc -> (acc, [y])
mapAccumLF acc -> x -> (acc, y)
f = \x
x acc -> (acc, [y])
r -> (acc -> (acc, [y])) -> acc -> (acc, [y])
forall a b. (a -> b) -> a -> b
oneShot (\acc
s ->
let (acc
s', y
y) = acc -> x -> (acc, y)
f acc
s x
x
(acc
s'', [y]
ys) = acc -> (acc, [y])
r acc
s'
in (acc
s'', y
yy -> [y] -> [y]
forall a. a -> [a] -> [a]
:[y]
ys))
mapAccumR :: (acc -> x -> (acc, y))
-> acc
-> [x]
-> (acc, [y])
mapAccumR :: forall acc x y. (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
mapAccumR acc -> x -> (acc, y)
_ acc
s [] = (acc
s, [])
mapAccumR acc -> x -> (acc, y)
f acc
s (x
x:[x]
xs) = (acc
s'', y
yy -> [y] -> [y]
forall a. a -> [a] -> [a]
:[y]
ys)
where (acc
s'',y
y ) = acc -> x -> (acc, y)
f acc
s' x
x
(acc
s', [y]
ys) = (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
forall acc x y. (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])
mapAccumR acc -> x -> (acc, y)
f acc
s [x]
xs
insert :: Ord a => a -> [a] -> [a]
insert :: forall a. Ord a => a -> [a] -> [a]
insert a
e [a]
ls = (a -> a -> Ordering) -> a -> [a] -> [a]
forall a. (a -> a -> Ordering) -> a -> [a] -> [a]
insertBy (a -> a -> Ordering
forall a. Ord a => a -> a -> Ordering
compare) a
e [a]
ls
insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]
insertBy :: forall a. (a -> a -> Ordering) -> a -> [a] -> [a]
insertBy a -> a -> Ordering
_ a
x [] = [a
x]
insertBy a -> a -> Ordering
cmp a
x ys :: [a]
ys@(a
y:[a]
ys')
= case a -> a -> Ordering
cmp a
x a
y of
Ordering
GT -> a
y a -> [a] -> [a]
forall a. a -> [a] -> [a]
: (a -> a -> Ordering) -> a -> [a] -> [a]
forall a. (a -> a -> Ordering) -> a -> [a] -> [a]
insertBy a -> a -> Ordering
cmp a
x [a]
ys'
Ordering
_ -> a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
ys
maximumBy :: (a -> a -> Ordering) -> [a] -> a
maximumBy :: forall a. (a -> a -> Ordering) -> [a] -> a
maximumBy a -> a -> Ordering
_ [] = [Char] -> a
forall a. [Char] -> a
errorWithoutStackTrace [Char]
"List.maximumBy: empty list"
maximumBy a -> a -> Ordering
cmp [a]
xs = (a -> a -> a) -> [a] -> a
forall a. HasCallStack => (a -> a -> a) -> [a] -> a
foldl1 a -> a -> a
maxBy [a]
xs
where
maxBy :: a -> a -> a
maxBy a
x a
y = case a -> a -> Ordering
cmp a
x a
y of
Ordering
GT -> a
x
Ordering
_ -> a
y
minimumBy :: (a -> a -> Ordering) -> [a] -> a
minimumBy :: forall a. (a -> a -> Ordering) -> [a] -> a
minimumBy a -> a -> Ordering
_ [] = [Char] -> a
forall a. [Char] -> a
errorWithoutStackTrace [Char]
"List.minimumBy: empty list"
minimumBy a -> a -> Ordering
cmp [a]
xs = (a -> a -> a) -> [a] -> a
forall a. HasCallStack => (a -> a -> a) -> [a] -> a
foldl1 a -> a -> a
minBy [a]
xs
where
minBy :: a -> a -> a
minBy a
x a
y = case a -> a -> Ordering
cmp a
x a
y of
Ordering
GT -> a
y
Ordering
_ -> a
x
genericLength :: (Num i) => [a] -> i
{-# NOINLINE [2] genericLength #-}
genericLength :: forall i a. Num i => [a] -> i
genericLength [] = i
0
genericLength (a
_:[a]
l) = i
1 i -> i -> i
forall a. Num a => a -> a -> a
+ [a] -> i
forall i a. Num i => [a] -> i
genericLength [a]
l
{-# RULES
"genericLengthInt" genericLength = (strictGenericLength :: [a] -> Int);
"genericLengthInteger" genericLength = (strictGenericLength :: [a] -> Integer);
#-}
strictGenericLength :: (Num i) => [b] -> i
strictGenericLength :: forall i a. Num i => [a] -> i
strictGenericLength [b]
l = [b] -> i -> i
forall {t} {a}. Num t => [a] -> t -> t
gl [b]
l i
0
where
gl :: [a] -> t -> t
gl [] t
a = t
a
gl (a
_:[a]
xs) t
a = let a' :: t
a' = t
a t -> t -> t
forall a. Num a => a -> a -> a
+ t
1 in t
a' t -> t -> t
forall a b. a -> b -> b
`seq` [a] -> t -> t
gl [a]
xs t
a'
{-# INLINABLE strictGenericLength #-}
genericTake :: (Integral i) => i -> [a] -> [a]
genericTake :: forall i a. Integral i => i -> [a] -> [a]
genericTake i
n [a]
_ | i
n i -> i -> Bool
forall a. Ord a => a -> a -> Bool
<= i
0 = []
genericTake i
_ [] = []
genericTake i
n (a
x:[a]
xs) = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: i -> [a] -> [a]
forall i a. Integral i => i -> [a] -> [a]
genericTake (i
ni -> i -> i
forall a. Num a => a -> a -> a
-i
1) [a]
xs
{-# INLINABLE genericTake #-}
genericDrop :: (Integral i) => i -> [a] -> [a]
genericDrop :: forall i a. Integral i => i -> [a] -> [a]
genericDrop i
n [a]
xs | i
n i -> i -> Bool
forall a. Ord a => a -> a -> Bool
<= i
0 = [a]
xs
genericDrop i
_ [] = []
genericDrop i
n (a
_:[a]
xs) = i -> [a] -> [a]
forall i a. Integral i => i -> [a] -> [a]
genericDrop (i
ni -> i -> i
forall a. Num a => a -> a -> a
-i
1) [a]
xs
{-# INLINABLE genericDrop #-}
genericSplitAt :: (Integral i) => i -> [a] -> ([a], [a])
genericSplitAt :: forall i a. Integral i => i -> [a] -> ([a], [a])
genericSplitAt i
n [a]
xs | i
n i -> i -> Bool
forall a. Ord a => a -> a -> Bool
<= i
0 = ([],[a]
xs)
genericSplitAt i
_ [] = ([],[])
genericSplitAt i
n (a
x:[a]
xs) = (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
xs',[a]
xs'') where
([a]
xs',[a]
xs'') = i -> [a] -> ([a], [a])
forall i a. Integral i => i -> [a] -> ([a], [a])
genericSplitAt (i
ni -> i -> i
forall a. Num a => a -> a -> a
-i
1) [a]
xs
{-# INLINABLE genericSplitAt #-}
genericIndex :: (Integral i) => [a] -> i -> a
genericIndex :: forall i a. Integral i => [a] -> i -> a
genericIndex (a
x:[a]
_) i
0 = a
x
genericIndex (a
_:[a]
xs) i
n
| i
n i -> i -> Bool
forall a. Ord a => a -> a -> Bool
> i
0 = [a] -> i -> a
forall i a. Integral i => [a] -> i -> a
genericIndex [a]
xs (i
ni -> i -> i
forall a. Num a => a -> a -> a
-i
1)
| Bool
otherwise = [Char] -> a
forall a. [Char] -> a
errorWithoutStackTrace [Char]
"List.genericIndex: negative argument."
genericIndex [a]
_ i
_ = [Char] -> a
forall a. [Char] -> a
errorWithoutStackTrace [Char]
"List.genericIndex: index too large."
{-# INLINABLE genericIndex #-}
genericReplicate :: (Integral i) => i -> a -> [a]
genericReplicate :: forall i a. Integral i => i -> a -> [a]
genericReplicate i
n a
x = i -> [a] -> [a]
forall i a. Integral i => i -> [a] -> [a]
genericTake i
n (a -> [a]
forall a. a -> [a]
repeat a
x)
{-# INLINABLE genericReplicate #-}
{-# INLINE zip4 #-}
zip4 :: [a] -> [b] -> [c] -> [d] -> [(a,b,c,d)]
zip4 :: forall a b c d. [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)]
zip4 = (a -> b -> c -> d -> (a, b, c, d))
-> [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)]
forall a b c d e.
(a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]
zipWith4 (,,,)
{-# INLINE zip5 #-}
zip5 :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a,b,c,d,e)]
zip5 :: forall a b c d e.
[a] -> [b] -> [c] -> [d] -> [e] -> [(a, b, c, d, e)]
zip5 = (a -> b -> c -> d -> e -> (a, b, c, d, e))
-> [a] -> [b] -> [c] -> [d] -> [e] -> [(a, b, c, d, e)]
forall a b c d e f.
(a -> b -> c -> d -> e -> f)
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f]
zipWith5 (,,,,)
{-# INLINE zip6 #-}
zip6 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] ->
[(a,b,c,d,e,f)]
zip6 :: forall a b c d e f.
[a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [(a, b, c, d, e, f)]
zip6 = (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [(a, b, c, d, e, f)]
forall a b c d e f g.
(a -> b -> c -> d -> e -> f -> g)
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g]
zipWith6 (,,,,,)
{-# INLINE zip7 #-}
zip7 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] ->
[g] -> [(a,b,c,d,e,f,g)]
zip7 :: forall a b c d e f g.
[a]
-> [b]
-> [c]
-> [d]
-> [e]
-> [f]
-> [g]
-> [(a, b, c, d, e, f, g)]
zip7 = (a -> b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> [a]
-> [b]
-> [c]
-> [d]
-> [e]
-> [f]
-> [g]
-> [(a, b, c, d, e, f, g)]
forall a b c d e f g h.
(a -> b -> c -> d -> e -> f -> g -> h)
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h]
zipWith7 (,,,,,,)
{-# NOINLINE [1] zipWith4 #-}
zipWith4 :: (a->b->c->d->e) -> [a]->[b]->[c]->[d]->[e]
zipWith4 :: forall a b c d e.
(a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]
zipWith4 a -> b -> c -> d -> e
z (a
a:[a]
as) (b
b:[b]
bs) (c
c:[c]
cs) (d
d:[d]
ds)
= a -> b -> c -> d -> e
z a
a b
b c
c d
d e -> [e] -> [e]
forall a. a -> [a] -> [a]
: (a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]
forall a b c d e.
(a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]
zipWith4 a -> b -> c -> d -> e
z [a]
as [b]
bs [c]
cs [d]
ds
zipWith4 a -> b -> c -> d -> e
_ [a]
_ [b]
_ [c]
_ [d]
_ = []
{-# NOINLINE [1] zipWith5 #-}
zipWith5 :: (a->b->c->d->e->f) ->
[a]->[b]->[c]->[d]->[e]->[f]
zipWith5 :: forall a b c d e f.
(a -> b -> c -> d -> e -> f)
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f]
zipWith5 a -> b -> c -> d -> e -> f
z (a
a:[a]
as) (b
b:[b]
bs) (c
c:[c]
cs) (d
d:[d]
ds) (e
e:[e]
es)
= a -> b -> c -> d -> e -> f
z a
a b
b c
c d
d e
e f -> [f] -> [f]
forall a. a -> [a] -> [a]
: (a -> b -> c -> d -> e -> f)
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f]
forall a b c d e f.
(a -> b -> c -> d -> e -> f)
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f]
zipWith5 a -> b -> c -> d -> e -> f
z [a]
as [b]
bs [c]
cs [d]
ds [e]
es
zipWith5 a -> b -> c -> d -> e -> f
_ [a]
_ [b]
_ [c]
_ [d]
_ [e]
_ = []
{-# NOINLINE [1] zipWith6 #-}
zipWith6 :: (a->b->c->d->e->f->g) ->
[a]->[b]->[c]->[d]->[e]->[f]->[g]
zipWith6 :: forall a b c d e f g.
(a -> b -> c -> d -> e -> f -> g)
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g]
zipWith6 a -> b -> c -> d -> e -> f -> g
z (a
a:[a]
as) (b
b:[b]
bs) (c
c:[c]
cs) (d
d:[d]
ds) (e
e:[e]
es) (f
f:[f]
fs)
= a -> b -> c -> d -> e -> f -> g
z a
a b
b c
c d
d e
e f
f g -> [g] -> [g]
forall a. a -> [a] -> [a]
: (a -> b -> c -> d -> e -> f -> g)
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g]
forall a b c d e f g.
(a -> b -> c -> d -> e -> f -> g)
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g]
zipWith6 a -> b -> c -> d -> e -> f -> g
z [a]
as [b]
bs [c]
cs [d]
ds [e]
es [f]
fs
zipWith6 a -> b -> c -> d -> e -> f -> g
_ [a]
_ [b]
_ [c]
_ [d]
_ [e]
_ [f]
_ = []
{-# NOINLINE [1] zipWith7 #-}
zipWith7 :: (a->b->c->d->e->f->g->h) ->
[a]->[b]->[c]->[d]->[e]->[f]->[g]->[h]
zipWith7 :: forall a b c d e f g h.
(a -> b -> c -> d -> e -> f -> g -> h)
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h]
zipWith7 a -> b -> c -> d -> e -> f -> g -> h
z (a
a:[a]
as) (b
b:[b]
bs) (c
c:[c]
cs) (d
d:[d]
ds) (e
e:[e]
es) (f
f:[f]
fs) (g
g:[g]
gs)
= a -> b -> c -> d -> e -> f -> g -> h
z a
a b
b c
c d
d e
e f
f g
g h -> [h] -> [h]
forall a. a -> [a] -> [a]
: (a -> b -> c -> d -> e -> f -> g -> h)
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h]
forall a b c d e f g h.
(a -> b -> c -> d -> e -> f -> g -> h)
-> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h]
zipWith7 a -> b -> c -> d -> e -> f -> g -> h
z [a]
as [b]
bs [c]
cs [d]
ds [e]
es [f]
fs [g]
gs
zipWith7 a -> b -> c -> d -> e -> f -> g -> h
_ [a]
_ [b]
_ [c]
_ [d]
_ [e]
_ [f]
_ [g]
_ = []
{-# INLINE [0] zipWith4FB #-}
zipWith4FB :: (e->xs->xs') -> (a->b->c->d->e) ->
a->b->c->d->xs->xs'
zipWith4FB :: forall e xs xs' a b c d.
(e -> xs -> xs')
-> (a -> b -> c -> d -> e) -> a -> b -> c -> d -> xs -> xs'
zipWith4FB e -> xs -> xs'
cons a -> b -> c -> d -> e
func = \a
a b
b c
c d
d xs
r -> (a -> b -> c -> d -> e
func a
a b
b c
c d
d) e -> xs -> xs'
`cons` xs
r
{-# INLINE [0] zipWith5FB #-}
zipWith5FB :: (f->xs->xs') -> (a->b->c->d->e->f) ->
a->b->c->d->e->xs->xs'
zipWith5FB :: forall f xs xs' a b c d e.
(f -> xs -> xs')
-> (a -> b -> c -> d -> e -> f)
-> a
-> b
-> c
-> d
-> e
-> xs
-> xs'
zipWith5FB f -> xs -> xs'
cons a -> b -> c -> d -> e -> f
func = \a
a b
b c
c d
d e
e xs
r -> (a -> b -> c -> d -> e -> f
func a
a b
b c
c d
d e
e) f -> xs -> xs'
`cons` xs
r
{-# INLINE [0] zipWith6FB #-}
zipWith6FB :: (g->xs->xs') -> (a->b->c->d->e->f->g) ->
a->b->c->d->e->f->xs->xs'
zipWith6FB :: forall g xs xs' a b c d e f.
(g -> xs -> xs')
-> (a -> b -> c -> d -> e -> f -> g)
-> a
-> b
-> c
-> d
-> e
-> f
-> xs
-> xs'
zipWith6FB g -> xs -> xs'
cons a -> b -> c -> d -> e -> f -> g
func = \a
a b
b c
c d
d e
e f
f xs
r -> (a -> b -> c -> d -> e -> f -> g
func a
a b
b c
c d
d e
e f
f) g -> xs -> xs'
`cons` xs
r
{-# INLINE [0] zipWith7FB #-}
zipWith7FB :: (h->xs->xs') -> (a->b->c->d->e->f->g->h) ->
a->b->c->d->e->f->g->xs->xs'
zipWith7FB :: forall h xs xs' a b c d e f g.
(h -> xs -> xs')
-> (a -> b -> c -> d -> e -> f -> g -> h)
-> a
-> b
-> c
-> d
-> e
-> f
-> g
-> xs
-> xs'
zipWith7FB h -> xs -> xs'
cons a -> b -> c -> d -> e -> f -> g -> h
func = \a
a b
b c
c d
d e
e f
f g
g xs
r -> (a -> b -> c -> d -> e -> f -> g -> h
func a
a b
b c
c d
d e
e f
f g
g) h -> xs -> xs'
`cons` xs
r
{-# INLINE [0] foldr4 #-}
foldr4 :: (a->b->c->d->e->e) ->
e->[a]->[b]->[c]->[d]->e
foldr4 :: forall a b c d e.
(a -> b -> c -> d -> e -> e) -> e -> [a] -> [b] -> [c] -> [d] -> e
foldr4 a -> b -> c -> d -> e -> e
k e
z = [a] -> [b] -> [c] -> [d] -> e
go
where
go :: [a] -> [b] -> [c] -> [d] -> e
go (a
a:[a]
as) (b
b:[b]
bs) (c
c:[c]
cs) (d
d:[d]
ds) = a -> b -> c -> d -> e -> e
k a
a b
b c
c d
d ([a] -> [b] -> [c] -> [d] -> e
go [a]
as [b]
bs [c]
cs [d]
ds)
go [a]
_ [b]
_ [c]
_ [d]
_ = e
z
{-# INLINE [0] foldr5 #-}
foldr5 :: (a->b->c->d->e->f->f) ->
f->[a]->[b]->[c]->[d]->[e]->f
foldr5 :: forall a b c d e f.
(a -> b -> c -> d -> e -> f -> f)
-> f -> [a] -> [b] -> [c] -> [d] -> [e] -> f
foldr5 a -> b -> c -> d -> e -> f -> f
k f
z = [a] -> [b] -> [c] -> [d] -> [e] -> f
go
where
go :: [a] -> [b] -> [c] -> [d] -> [e] -> f
go (a
a:[a]
as) (b
b:[b]
bs) (c
c:[c]
cs) (d
d:[d]
ds) (e
e:[e]
es) = a -> b -> c -> d -> e -> f -> f
k a
a b
b c
c d
d e
e ([a] -> [b] -> [c] -> [d] -> [e] -> f
go [a]
as [b]
bs [c]
cs [d]
ds [e]
es)
go [a]
_ [b]
_ [c]
_ [d]
_ [e]
_ = f
z
{-# INLINE [0] foldr6 #-}
foldr6 :: (a->b->c->d->e->f->g->g) ->
g->[a]->[b]->[c]->[d]->[e]->[f]->g
foldr6 :: forall a b c d e f g.
(a -> b -> c -> d -> e -> f -> g -> g)
-> g -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> g
foldr6 a -> b -> c -> d -> e -> f -> g -> g
k g
z = [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> g
go
where
go :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> g
go (a
a:[a]
as) (b
b:[b]
bs) (c
c:[c]
cs) (d
d:[d]
ds) (e
e:[e]
es) (f
f:[f]
fs) = a -> b -> c -> d -> e -> f -> g -> g
k a
a b
b c
c d
d e
e f
f (
[a] -> [b] -> [c] -> [d] -> [e] -> [f] -> g
go [a]
as [b]
bs [c]
cs [d]
ds [e]
es [f]
fs)
go [a]
_ [b]
_ [c]
_ [d]
_ [e]
_ [f]
_ = g
z
{-# INLINE [0] foldr7 #-}
foldr7 :: (a->b->c->d->e->f->g->h->h) ->
h->[a]->[b]->[c]->[d]->[e]->[f]->[g]->h
foldr7 :: forall a b c d e f g h.
(a -> b -> c -> d -> e -> f -> g -> h -> h)
-> h -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> h
foldr7 a -> b -> c -> d -> e -> f -> g -> h -> h
k h
z = [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> h
go
where
go :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> h
go (a
a:[a]
as) (b
b:[b]
bs) (c
c:[c]
cs) (d
d:[d]
ds) (e
e:[e]
es) (f
f:[f]
fs) (g
g:[g]
gs) = a -> b -> c -> d -> e -> f -> g -> h -> h
k a
a b
b c
c d
d e
e f
f g
g (
[a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> h
go [a]
as [b]
bs [c]
cs [d]
ds [e]
es [f]
fs [g]
gs)
go [a]
_ [b]
_ [c]
_ [d]
_ [e]
_ [f]
_ [g]
_ = h
z
foldr4_left :: (a->b->c->d->e->f)->
f->a->([b]->[c]->[d]->e)->
[b]->[c]->[d]->f
foldr4_left :: forall a b c d e f.
(a -> b -> c -> d -> e -> f)
-> f -> a -> ([b] -> [c] -> [d] -> e) -> [b] -> [c] -> [d] -> f
foldr4_left a -> b -> c -> d -> e -> f
k f
_z a
a [b] -> [c] -> [d] -> e
r (b
b:[b]
bs) (c
c:[c]
cs) (d
d:[d]
ds) = a -> b -> c -> d -> e -> f
k a
a b
b c
c d
d ([b] -> [c] -> [d] -> e
r [b]
bs [c]
cs [d]
ds)
foldr4_left a -> b -> c -> d -> e -> f
_ f
z a
_ [b] -> [c] -> [d] -> e
_ [b]
_ [c]
_ [d]
_ = f
z
foldr5_left :: (a->b->c->d->e->f->g)->
g->a->([b]->[c]->[d]->[e]->f)->
[b]->[c]->[d]->[e]->g
foldr5_left :: forall a b c d e f g.
(a -> b -> c -> d -> e -> f -> g)
-> g
-> a
-> ([b] -> [c] -> [d] -> [e] -> f)
-> [b]
-> [c]
-> [d]
-> [e]
-> g
foldr5_left a -> b -> c -> d -> e -> f -> g
k g
_z a
a [b] -> [c] -> [d] -> [e] -> f
r (b
b:[b]
bs) (c
c:[c]
cs) (d
d:[d]
ds) (e
e:[e]
es) = a -> b -> c -> d -> e -> f -> g
k a
a b
b c
c d
d e
e ([b] -> [c] -> [d] -> [e] -> f
r [b]
bs [c]
cs [d]
ds [e]
es)
foldr5_left a -> b -> c -> d -> e -> f -> g
_ g
z a
_ [b] -> [c] -> [d] -> [e] -> f
_ [b]
_ [c]
_ [d]
_ [e]
_ = g
z
foldr6_left :: (a->b->c->d->e->f->g->h)->
h->a->([b]->[c]->[d]->[e]->[f]->g)->
[b]->[c]->[d]->[e]->[f]->h
foldr6_left :: forall a b c d e f g h.
(a -> b -> c -> d -> e -> f -> g -> h)
-> h
-> a
-> ([b] -> [c] -> [d] -> [e] -> [f] -> g)
-> [b]
-> [c]
-> [d]
-> [e]
-> [f]
-> h
foldr6_left a -> b -> c -> d -> e -> f -> g -> h
k h
_z a
a [b] -> [c] -> [d] -> [e] -> [f] -> g
r (b
b:[b]
bs) (c
c:[c]
cs) (d
d:[d]
ds) (e
e:[e]
es) (f
f:[f]
fs) =
a -> b -> c -> d -> e -> f -> g -> h
k a
a b
b c
c d
d e
e f
f ([b] -> [c] -> [d] -> [e] -> [f] -> g
r [b]
bs [c]
cs [d]
ds [e]
es [f]
fs)
foldr6_left a -> b -> c -> d -> e -> f -> g -> h
_ h
z a
_ [b] -> [c] -> [d] -> [e] -> [f] -> g
_ [b]
_ [c]
_ [d]
_ [e]
_ [f]
_ = h
z
foldr7_left :: (a->b->c->d->e->f->g->h->i)->
i->a->([b]->[c]->[d]->[e]->[f]->[g]->h)->
[b]->[c]->[d]->[e]->[f]->[g]->i
foldr7_left :: forall a b c d e f g h i.
(a -> b -> c -> d -> e -> f -> g -> h -> i)
-> i
-> a
-> ([b] -> [c] -> [d] -> [e] -> [f] -> [g] -> h)
-> [b]
-> [c]
-> [d]
-> [e]
-> [f]
-> [g]
-> i
foldr7_left a -> b -> c -> d -> e -> f -> g -> h -> i
k i
_z a
a [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> h
r (b
b:[b]
bs) (c
c:[c]
cs) (d
d:[d]
ds) (e
e:[e]
es) (f
f:[f]
fs) (g
g:[g]
gs) =
a -> b -> c -> d -> e -> f -> g -> h -> i
k a
a b
b c
c d
d e
e f
f g
g ([b] -> [c] -> [d] -> [e] -> [f] -> [g] -> h
r [b]
bs [c]
cs [d]
ds [e]
es [f]
fs [g]
gs)
foldr7_left a -> b -> c -> d -> e -> f -> g -> h -> i
_ i
z a
_ [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> h
_ [b]
_ [c]
_ [d]
_ [e]
_ [f]
_ [g]
_ = i
z
{-# RULES
"foldr4/left" forall k z (g::forall b.(a->b->b)->b->b).
foldr4 k z (build g) = g (foldr4_left k z) (\_ _ _ -> z)
"foldr5/left" forall k z (g::forall b.(a->b->b)->b->b).
foldr5 k z (build g) = g (foldr5_left k z) (\_ _ _ _ -> z)
"foldr6/left" forall k z (g::forall b.(a->b->b)->b->b).
foldr6 k z (build g) = g (foldr6_left k z) (\_ _ _ _ _ -> z)
"foldr7/left" forall k z (g::forall b.(a->b->b)->b->b).
foldr7 k z (build g) = g (foldr7_left k z) (\_ _ _ _ _ _ -> z)
"zipWith4" [~1] forall f as bs cs ds.
zipWith4 f as bs cs ds = build (\c n ->
foldr4 (zipWith4FB c f) n as bs cs ds)
"zipWith5" [~1] forall f as bs cs ds es.
zipWith5 f as bs cs ds es = build (\c n ->
foldr5 (zipWith5FB c f) n as bs cs ds es)
"zipWith6" [~1] forall f as bs cs ds es fs.
zipWith6 f as bs cs ds es fs = build (\c n ->
foldr6 (zipWith6FB c f) n as bs cs ds es fs)
"zipWith7" [~1] forall f as bs cs ds es fs gs.
zipWith7 f as bs cs ds es fs gs = build (\c n ->
foldr7 (zipWith7FB c f) n as bs cs ds es fs gs)
"zipWith4List" [1] forall f. foldr4 (zipWith4FB (:) f) [] = zipWith4 f
"zipWith5List" [1] forall f. foldr5 (zipWith5FB (:) f) [] = zipWith5 f
"zipWith6List" [1] forall f. foldr6 (zipWith6FB (:) f) [] = zipWith6 f
"zipWith7List" [1] forall f. foldr7 (zipWith7FB (:) f) [] = zipWith7 f
#-}
{-# INLINE unzip4 #-}
unzip4 :: [(a,b,c,d)] -> ([a],[b],[c],[d])
unzip4 :: forall a b c d. [(a, b, c, d)] -> ([a], [b], [c], [d])
unzip4 = ((a, b, c, d) -> ([a], [b], [c], [d]) -> ([a], [b], [c], [d]))
-> ([a], [b], [c], [d]) -> [(a, b, c, d)] -> ([a], [b], [c], [d])
forall a b. (a -> b -> b) -> b -> [a] -> b
foldr (\(a
a,b
b,c
c,d
d) ~([a]
as,[b]
bs,[c]
cs,[d]
ds) ->
(a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
as,b
bb -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
bs,c
cc -> [c] -> [c]
forall a. a -> [a] -> [a]
:[c]
cs,d
dd -> [d] -> [d]
forall a. a -> [a] -> [a]
:[d]
ds))
([],[],[],[])
{-# INLINE unzip5 #-}
unzip5 :: [(a,b,c,d,e)] -> ([a],[b],[c],[d],[e])
unzip5 :: forall a b c d e. [(a, b, c, d, e)] -> ([a], [b], [c], [d], [e])
unzip5 = ((a, b, c, d, e)
-> ([a], [b], [c], [d], [e]) -> ([a], [b], [c], [d], [e]))
-> ([a], [b], [c], [d], [e])
-> [(a, b, c, d, e)]
-> ([a], [b], [c], [d], [e])
forall a b. (a -> b -> b) -> b -> [a] -> b
foldr (\(a
a,b
b,c
c,d
d,e
e) ~([a]
as,[b]
bs,[c]
cs,[d]
ds,[e]
es) ->
(a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
as,b
bb -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
bs,c
cc -> [c] -> [c]
forall a. a -> [a] -> [a]
:[c]
cs,d
dd -> [d] -> [d]
forall a. a -> [a] -> [a]
:[d]
ds,e
ee -> [e] -> [e]
forall a. a -> [a] -> [a]
:[e]
es))
([],[],[],[],[])
{-# INLINE unzip6 #-}
unzip6 :: [(a,b,c,d,e,f)] -> ([a],[b],[c],[d],[e],[f])
unzip6 :: forall a b c d e f.
[(a, b, c, d, e, f)] -> ([a], [b], [c], [d], [e], [f])
unzip6 = ((a, b, c, d, e, f)
-> ([a], [b], [c], [d], [e], [f])
-> ([a], [b], [c], [d], [e], [f]))
-> ([a], [b], [c], [d], [e], [f])
-> [(a, b, c, d, e, f)]
-> ([a], [b], [c], [d], [e], [f])
forall a b. (a -> b -> b) -> b -> [a] -> b
foldr (\(a
a,b
b,c
c,d
d,e
e,f
f) ~([a]
as,[b]
bs,[c]
cs,[d]
ds,[e]
es,[f]
fs) ->
(a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
as,b
bb -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
bs,c
cc -> [c] -> [c]
forall a. a -> [a] -> [a]
:[c]
cs,d
dd -> [d] -> [d]
forall a. a -> [a] -> [a]
:[d]
ds,e
ee -> [e] -> [e]
forall a. a -> [a] -> [a]
:[e]
es,f
ff -> [f] -> [f]
forall a. a -> [a] -> [a]
:[f]
fs))
([],[],[],[],[],[])
{-# INLINE unzip7 #-}
unzip7 :: [(a,b,c,d,e,f,g)] -> ([a],[b],[c],[d],[e],[f],[g])
unzip7 :: forall a b c d e f g.
[(a, b, c, d, e, f, g)] -> ([a], [b], [c], [d], [e], [f], [g])
unzip7 = ((a, b, c, d, e, f, g)
-> ([a], [b], [c], [d], [e], [f], [g])
-> ([a], [b], [c], [d], [e], [f], [g]))
-> ([a], [b], [c], [d], [e], [f], [g])
-> [(a, b, c, d, e, f, g)]
-> ([a], [b], [c], [d], [e], [f], [g])
forall a b. (a -> b -> b) -> b -> [a] -> b
foldr (\(a
a,b
b,c
c,d
d,e
e,f
f,g
g) ~([a]
as,[b]
bs,[c]
cs,[d]
ds,[e]
es,[f]
fs,[g]
gs) ->
(a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
as,b
bb -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
bs,c
cc -> [c] -> [c]
forall a. a -> [a] -> [a]
:[c]
cs,d
dd -> [d] -> [d]
forall a. a -> [a] -> [a]
:[d]
ds,e
ee -> [e] -> [e]
forall a. a -> [a] -> [a]
:[e]
es,f
ff -> [f] -> [f]
forall a. a -> [a] -> [a]
:[f]
fs,g
gg -> [g] -> [g]
forall a. a -> [a] -> [a]
:[g]
gs))
([],[],[],[],[],[],[])
deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
deleteFirstsBy :: forall a. (a -> a -> Bool) -> [a] -> [a] -> [a]
deleteFirstsBy a -> a -> Bool
eq = ([a] -> a -> [a]) -> [a] -> [a] -> [a]
forall a b. (b -> a -> b) -> b -> [a] -> b
foldl ((a -> [a] -> [a]) -> [a] -> a -> [a]
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> a -> Bool) -> a -> [a] -> [a]
forall a. (a -> a -> Bool) -> a -> [a] -> [a]
deleteBy a -> a -> Bool
eq))
group :: Eq a => [a] -> [[a]]
group :: forall a. Eq a => [a] -> [[a]]
group = (a -> a -> Bool) -> [a] -> [[a]]
forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
groupBy :: (a -> a -> Bool) -> [a] -> [[a]]
groupBy :: forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy a -> a -> Bool
_ [] = []
groupBy a -> a -> Bool
eq (a
x:[a]
xs) = (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
ys) [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: (a -> a -> Bool) -> [a] -> [[a]]
forall a. (a -> a -> Bool) -> [a] -> [[a]]
groupBy a -> a -> Bool
eq [a]
zs
where ([a]
ys,[a]
zs) = (a -> Bool) -> [a] -> ([a], [a])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (a -> a -> Bool
eq a
x) [a]
xs
inits :: [a] -> [[a]]
inits :: forall a. [a] -> [[a]]
inits = (SnocBuilder a -> [a]) -> [SnocBuilder a] -> [[a]]
forall a b. (a -> b) -> [a] -> [b]
map SnocBuilder a -> [a]
forall a. SnocBuilder a -> [a]
toListSB ([SnocBuilder a] -> [[a]])
-> ([a] -> [SnocBuilder a]) -> [a] -> [[a]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SnocBuilder a -> a -> SnocBuilder a)
-> SnocBuilder a -> [a] -> [SnocBuilder a]
forall b a. (b -> a -> b) -> b -> [a] -> [b]
scanl' SnocBuilder a -> a -> SnocBuilder a
forall a. SnocBuilder a -> a -> SnocBuilder a
snocSB SnocBuilder a
forall a. SnocBuilder a
emptySB
{-# NOINLINE inits #-}
tails :: [a] -> [[a]]
{-# INLINABLE tails #-}
tails :: forall a. [a] -> [[a]]
tails [a]
lst = (forall b. ([a] -> b -> b) -> b -> b) -> [[a]]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build (\[a] -> b -> b
c b
n ->
let tailsGo :: [a] -> b
tailsGo [a]
xs = [a]
xs [a] -> b -> b
`c` case [a]
xs of
[] -> b
n
a
_ : [a]
xs' -> [a] -> b
tailsGo [a]
xs'
in [a] -> b
tailsGo [a]
lst)
subsequences :: [a] -> [[a]]
subsequences :: forall a. [a] -> [[a]]
subsequences [a]
xs = [] [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [a] -> [[a]]
forall a. [a] -> [[a]]
nonEmptySubsequences [a]
xs
nonEmptySubsequences :: [a] -> [[a]]
nonEmptySubsequences :: forall a. [a] -> [[a]]
nonEmptySubsequences [] = []
nonEmptySubsequences (a
x:[a]
xs) = [a
x] [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: ([a] -> [[a]] -> [[a]]) -> [[a]] -> [[a]] -> [[a]]
forall a b. (a -> b -> b) -> b -> [a] -> b
foldr [a] -> [[a]] -> [[a]]
f [] ([a] -> [[a]]
forall a. [a] -> [[a]]
nonEmptySubsequences [a]
xs)
where f :: [a] -> [[a]] -> [[a]]
f [a]
ys [[a]]
r = [a]
ys [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: (a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
ys) [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [[a]]
r
permutations :: [a] -> [[a]]
permutations :: forall a. [a] -> [[a]]
permutations [a]
xs0 = [a]
xs0 [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [a] -> [a] -> [[a]]
forall a. [a] -> [a] -> [[a]]
perms [a]
xs0 []
where
perms :: forall a. [a] -> [a] -> [[a]]
perms :: forall a. [a] -> [a] -> [[a]]
perms [] [a]
_ = []
perms (a
t:[a]
ts) [a]
is = ([a] -> [[a]] -> [[a]]) -> [[a]] -> [[a]] -> [[a]]
forall a b. (a -> b -> b) -> b -> [a] -> b
foldr [a] -> [[a]] -> [[a]]
interleave ([a] -> [a] -> [[a]]
forall a. [a] -> [a] -> [[a]]
perms [a]
ts (a
ta -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
is)) ([a] -> [[a]]
forall a. [a] -> [[a]]
permutations [a]
is)
where
interleave :: [a] -> [[a]] -> [[a]]
interleave :: [a] -> [[a]] -> [[a]]
interleave [a]
xs [[a]]
r = let ([a]
_,[[a]]
zs) = ([a] -> [a]) -> [a] -> [[a]] -> ([a], [[a]])
forall b. ([a] -> b) -> [a] -> [b] -> ([a], [b])
interleave' [a] -> [a]
forall a. a -> a
id [a]
xs [[a]]
r in [[a]]
zs
interleave' :: ([a] -> b) -> [a] -> [b] -> ([a], [b])
interleave' :: forall b. ([a] -> b) -> [a] -> [b] -> ([a], [b])
interleave' [a] -> b
_ [] [b]
r = ([a]
ts, [b]
r)
interleave' [a] -> b
f (a
y:[a]
ys) [b]
r = let ([a]
us,[b]
zs) = ([a] -> b) -> [a] -> [b] -> ([a], [b])
forall b. ([a] -> b) -> [a] -> [b] -> ([a], [b])
interleave' ([a] -> b
f ([a] -> b) -> ([a] -> [a]) -> [a] -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
ya -> [a] -> [a]
forall a. a -> [a] -> [a]
:)) [a]
ys [b]
r
in (a
ya -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
us, [a] -> b
f (a
ta -> [a] -> [a]
forall a. a -> [a] -> [a]
:a
ya -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
us) b -> [b] -> [b]
forall a. a -> [a] -> [a]
: [b]
zs)
sort :: (Ord a) => [a] -> [a]
sortBy :: (a -> a -> Ordering) -> [a] -> [a]
{-# INLINEABLE sort #-}
sort :: forall a. Ord a => [a] -> [a]
sort = (a -> a -> Bool) -> [a] -> [a]
forall a. (a -> a -> Bool) -> [a] -> [a]
actualSort a -> a -> Bool
forall a. Ord a => a -> a -> Bool
(>)
{-# INLINEABLE sortBy #-}
sortBy :: forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy a -> a -> Ordering
cmp = (a -> a -> Bool) -> [a] -> [a]
forall a. (a -> a -> Bool) -> [a] -> [a]
actualSort (\a
x a
y -> a -> a -> Ordering
cmp a
x a
y Ordering -> Ordering -> Bool
forall a. Eq a => a -> a -> Bool
== Ordering
GT)
actualSort :: (a -> a -> Bool) -> [a] -> [a]
actualSort :: forall a. (a -> a -> Bool) -> [a] -> [a]
actualSort a -> a -> Bool
gt [a]
ns
| [] <- [a]
ns = []
| [a
a] <- [a]
ns = [a
a]
| [a
a,a
b] <- [a]
ns = [a] -> [a] -> [a]
merge [a
a] [a
b]
| [a
a,a
b,a
c] <- [a]
ns = [a] -> [a] -> [a] -> [a]
merge3 [a
a] [a
b] [a
c]
| [a
a,a
b,a
c,a
d] <- [a]
ns = [a] -> [a] -> [a] -> [a] -> [a]
merge4 [a
a] [a
b] [a
c] [a
d]
| Bool
otherwise = [[a]] -> [a]
merge_all ([a] -> [[a]]
sequences [a]
ns)
where
sequences :: [a] -> [[a]]
sequences (a
a:a
b:[a]
xs)
| a
a a -> a -> Bool
`gt` a
b = a -> [a] -> [a] -> [[a]]
descending a
b [a
a] [a]
xs
| Bool
otherwise = a -> ([a] -> [a]) -> [a] -> [[a]]
ascending a
b (a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:) [a]
xs
sequences [a]
xs = [[a]
xs]
descending :: a -> [a] -> [a] -> [[a]]
descending a
a [a]
as (a
b:[a]
bs)
| a
a a -> a -> Bool
`gt` a
b = a -> [a] -> [a] -> [[a]]
descending a
b (a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
as) [a]
bs
descending a
a [a]
as [a]
bs = (a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
as)[a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [a] -> [[a]]
sequences [a]
bs
ascending :: a -> ([a] -> [a]) -> [a] -> [[a]]
ascending a
a [a] -> [a]
as (a
b:[a]
bs)
| Bool -> Bool
not (a
a a -> a -> Bool
`gt` a
b) = a -> ([a] -> [a]) -> [a] -> [[a]]
ascending a
b (\[a]
ys -> [a] -> [a]
as (a
aa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
ys)) [a]
bs
ascending a
a [a] -> [a]
as [a]
bs = let !x :: [a]
x = [a] -> [a]
as [a
a]
in [a]
x [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [a] -> [[a]]
sequences [a]
bs
merge_all :: [[a]] -> [a]
merge_all [[a]
x] = [a]
x
merge_all [[a]]
xs = [[a]] -> [a]
merge_all ([[a]] -> [[a]]
reduce_once [[a]]
xs)
reduce_once :: [[a]] -> [[a]]
reduce_once [] = []
reduce_once [[a]
a] = [[a]
a]
reduce_once [[a]
a,[a]
b] = [[a] -> [a] -> [a]
merge [a]
a [a]
b]
reduce_once [[a]
a,[a]
b,[a]
c] = [[a] -> [a] -> [a] -> [a]
merge3 [a]
a [a]
b [a]
c]
reduce_once [[a]
a,[a]
b,[a]
c,[a]
d,[a]
e] = [[a] -> [a] -> [a]
merge [a]
a [a]
b, [a] -> [a] -> [a] -> [a]
merge3 [a]
c [a]
d [a]
e]
reduce_once [[a]
a,[a]
b,[a]
c,[a]
d,[a]
e,[a]
f] = [[a] -> [a] -> [a] -> [a]
merge3 [a]
a [a]
b [a]
c, [a] -> [a] -> [a] -> [a]
merge3 [a]
d [a]
e [a]
f]
reduce_once ([a]
a:[a]
b:[a]
c:[a]
d:[[a]]
xs) = let !x :: [a]
x = [a] -> [a] -> [a] -> [a] -> [a]
merge4 [a]
a [a]
b [a]
c [a]
d
in [a]
x [a] -> [[a]] -> [[a]]
forall a. a -> [a] -> [a]
: [[a]] -> [[a]]
reduce_once [[a]]
xs
merge :: [a] -> [a] -> [a]
merge as :: [a]
as@(a
a:[a]
as') bs :: [a]
bs@(a
b:[a]
bs')
| a
a a -> a -> Bool
`gt` a
b = a
b a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a] -> [a]
merge [a]
as [a]
bs'
| Bool
otherwise = a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a] -> [a]
merge [a]
as' [a]
bs
merge [] [a]
bs = [a]
bs
merge [a]
as [] = [a]
as
merge3 :: [a] -> [a] -> [a] -> [a]
merge3 as :: [a]
as@(a
a:[a]
as') bs :: [a]
bs@(a
b:[a]
bs') [a]
cs
| a
a a -> a -> Bool
`gt` a
b = a -> [a] -> [a] -> [a] -> [a]
merge3X a
b [a]
as [a]
bs' [a]
cs
| Bool
otherwise = a -> [a] -> [a] -> [a] -> [a]
merge3X a
a [a]
as' [a]
bs [a]
cs
merge3 [] [a]
bs [a]
cs = [a] -> [a] -> [a]
merge [a]
bs [a]
cs
merge3 [a]
as [] [a]
cs = [a] -> [a] -> [a]
merge [a]
as [a]
cs
merge3X :: a -> [a] -> [a] -> [a] -> [a]
merge3X a
x [a]
as [a]
bs cs :: [a]
cs@(a
c:[a]
cs')
| a
x a -> a -> Bool
`gt` a
c = a
c a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a -> [a] -> [a] -> [a] -> [a]
merge3X a
x [a]
as [a]
bs [a]
cs'
| Bool
otherwise = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a] -> [a] -> [a]
merge3 [a]
as [a]
bs [a]
cs
merge3X a
x [a]
as [a]
bs [] = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a] -> [a]
merge [a]
as [a]
bs
merge3Y :: [a] -> a -> [a] -> [a] -> [a]
merge3Y as :: [a]
as@(a
a:[a]
as') a
y [a]
bs [a]
cs
| a
a a -> a -> Bool
`gt` a
y = a
y a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a] -> [a] -> [a]
merge3 [a]
as [a]
bs [a]
cs
| Bool
otherwise = a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> a -> [a] -> [a] -> [a]
merge3Y [a]
as' a
y [a]
bs [a]
cs
merge3Y [] a
x [a]
bs [a]
cs = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a] -> [a]
merge [a]
bs [a]
cs
merge4 :: [a] -> [a] -> [a] -> [a] -> [a]
merge4 as :: [a]
as@(a
a:[a]
as') bs :: [a]
bs@(a
b:[a]
bs') [a]
cs [a]
ds
| a
a a -> a -> Bool
`gt` a
b = a -> [a] -> [a] -> [a] -> [a] -> [a]
merge4X a
b [a]
as [a]
bs' [a]
cs [a]
ds
| Bool
otherwise = a -> [a] -> [a] -> [a] -> [a] -> [a]
merge4X a
a [a]
as' [a]
bs [a]
cs [a]
ds
merge4 [] [a]
bs [a]
cs [a]
ds = [a] -> [a] -> [a] -> [a]
merge3 [a]
bs [a]
cs [a]
ds
merge4 [a]
as [] [a]
cs [a]
ds = [a] -> [a] -> [a] -> [a]
merge3 [a]
as [a]
cs [a]
ds
merge4X :: a -> [a] -> [a] -> [a] -> [a] -> [a]
merge4X a
x [a]
as [a]
bs cs :: [a]
cs@(a
c:[a]
cs') ds :: [a]
ds@(a
d:[a]
ds')
| a
c a -> a -> Bool
`gt` a
d = a -> [a] -> [a] -> a -> [a] -> [a] -> [a]
merge4XY a
x [a]
as [a]
bs a
d [a]
cs [a]
ds'
| Bool
otherwise = a -> [a] -> [a] -> a -> [a] -> [a] -> [a]
merge4XY a
x [a]
as [a]
bs a
c [a]
cs' [a]
ds
merge4X a
x [a]
as [a]
bs [] [a]
ds = a -> [a] -> [a] -> [a] -> [a]
merge3X a
x [a]
as [a]
bs [a]
ds
merge4X a
x [a]
as [a]
bs [a]
cs [] = a -> [a] -> [a] -> [a] -> [a]
merge3X a
x [a]
as [a]
bs [a]
cs
merge4Y :: [a] -> [a] -> a -> [a] -> [a] -> [a]
merge4Y as :: [a]
as@(a
a:[a]
as') bs :: [a]
bs@(a
b:[a]
bs') a
y [a]
cs [a]
ds
| a
a a -> a -> Bool
`gt` a
b = a -> [a] -> [a] -> a -> [a] -> [a] -> [a]
merge4XY a
b [a]
as [a]
bs' a
y [a]
cs [a]
ds
| Bool
otherwise = a -> [a] -> [a] -> a -> [a] -> [a] -> [a]
merge4XY a
a [a]
as' [a]
bs a
y [a]
cs [a]
ds
merge4Y [a]
as [] a
y [a]
cs [a]
ds = [a] -> a -> [a] -> [a] -> [a]
merge3Y [a]
as a
y [a]
cs [a]
ds
merge4Y [] [a]
bs a
y [a]
cs [a]
ds = [a] -> a -> [a] -> [a] -> [a]
merge3Y [a]
bs a
y [a]
cs [a]
ds
merge4XY :: a -> [a] -> [a] -> a -> [a] -> [a] -> [a]
merge4XY a
x [a]
as [a]
bs a
y [a]
cs [a]
ds
| a
x a -> a -> Bool
`gt` a
y = a
y a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a -> [a] -> [a] -> [a] -> [a] -> [a]
merge4X a
x [a]
as [a]
bs [a]
cs [a]
ds
| Bool
otherwise = a
x a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a] -> [a] -> a -> [a] -> [a] -> [a]
merge4Y [a]
as [a]
bs a
y [a]
cs [a]
ds
sortOn :: Ord b => (a -> b) -> [a] -> [a]
sortOn :: forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn a -> b
f =
((b, a) -> a) -> [(b, a)] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (b, a) -> a
forall a b. (a, b) -> b
snd ([(b, a)] -> [a]) -> ([a] -> [(b, a)]) -> [a] -> [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((b, a) -> (b, a) -> Ordering) -> [(b, a)] -> [(b, a)]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (((b, a) -> b) -> (b, a) -> (b, a) -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing (b, a) -> b
forall a b. (a, b) -> a
fst) ([(b, a)] -> [(b, a)]) -> ([a] -> [(b, a)]) -> [a] -> [(b, a)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> (b, a)) -> [a] -> [(b, a)]
forall a b. (a -> b) -> [a] -> [b]
map (\a
x -> let y :: b
y = a -> b
f a
x in b
y b -> (b, a) -> (b, a)
forall a b. a -> b -> b
`seq` (b
y, a
x))
singleton :: a -> [a]
singleton :: forall a. a -> [a]
singleton a
x = [a
x]
unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
{-# INLINE unfoldr #-}
unfoldr :: forall b a. (b -> Maybe (a, b)) -> b -> [a]
unfoldr b -> Maybe (a, b)
f b
b0 = (forall b. (a -> b -> b) -> b -> b) -> [a]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build (\a -> b -> b
c b
n ->
let go :: b -> b
go b
b = case b -> Maybe (a, b)
f b
b of
Just (a
a, b
new_b) -> a
a a -> b -> b
`c` b -> b
go b
new_b
Maybe (a, b)
Nothing -> b
n
in b -> b
go b
b0)
lines :: String -> [String]
lines :: [Char] -> [[Char]]
lines [Char]
"" = []
lines [Char]
s = ([Char], [[Char]]) -> [[Char]]
forall {a}. (a, [a]) -> [a]
cons (case (Char -> Bool) -> [Char] -> ([Char], [Char])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\n') [Char]
s of
([Char]
l, [Char]
s') -> ([Char]
l, case [Char]
s' of
[] -> []
Char
_:[Char]
s'' -> [Char] -> [[Char]]
lines [Char]
s''))
where
cons :: (a, [a]) -> [a]
cons ~(a
h, [a]
t) = a
h a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
t
unlines :: [String] -> String
unlines :: [[Char]] -> [Char]
unlines [] = []
unlines ([Char]
l:[[Char]]
ls) = [Char]
l [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Char
'\n' Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: [[Char]] -> [Char]
unlines [[Char]]
ls
words :: String -> [String]
{-# NOINLINE [1] words #-}
words :: [Char] -> [[Char]]
words [Char]
s = case (Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isSpace [Char]
s of
[Char]
"" -> []
[Char]
s' -> [Char]
w [Char] -> [[Char]] -> [[Char]]
forall a. a -> [a] -> [a]
: [Char] -> [[Char]]
words [Char]
s''
where ([Char]
w, [Char]
s'') =
(Char -> Bool) -> [Char] -> ([Char], [Char])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break Char -> Bool
isSpace [Char]
s'
{-# RULES
"words" [~1] forall s . words s = build (\c n -> wordsFB c n s)
"wordsList" [1] wordsFB (:) [] = words
#-}
wordsFB :: ([Char] -> b -> b) -> b -> String -> b
{-# INLINE [0] wordsFB #-}
wordsFB :: forall b. ([Char] -> b -> b) -> b -> [Char] -> b
wordsFB [Char] -> b -> b
c b
n = [Char] -> b
go
where
go :: [Char] -> b
go [Char]
s = case (Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isSpace [Char]
s of
[Char]
"" -> b
n
[Char]
s' -> [Char]
w [Char] -> b -> b
`c` [Char] -> b
go [Char]
s''
where ([Char]
w, [Char]
s'') = (Char -> Bool) -> [Char] -> ([Char], [Char])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break Char -> Bool
isSpace [Char]
s'
unwords :: [String] -> String
{-# NOINLINE [1] unwords #-}
unwords :: [[Char]] -> [Char]
unwords [] = [Char]
""
unwords ([Char]
w:[[Char]]
ws) = [Char]
w [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [[Char]] -> [Char]
go [[Char]]
ws
where
go :: [[Char]] -> [Char]
go [] = [Char]
""
go ([Char]
v:[[Char]]
vs) = Char
' ' Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: ([Char]
v [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [[Char]] -> [Char]
go [[Char]]
vs)
{-# RULES
"unwords" [~1] forall ws .
unwords ws = tailUnwords (foldr unwordsFB "" ws)
"unwordsList" [1] forall ws .
tailUnwords (foldr unwordsFB "" ws) = unwords ws
#-}
{-# INLINE [0] tailUnwords #-}
tailUnwords :: String -> String
tailUnwords :: [Char] -> [Char]
tailUnwords [] = []
tailUnwords (Char
_:[Char]
xs) = [Char]
xs
{-# INLINE [0] unwordsFB #-}
unwordsFB :: String -> String -> String
unwordsFB :: [Char] -> [Char] -> [Char]
unwordsFB [Char]
w [Char]
r = Char
' ' Char -> [Char] -> [Char]
forall a. a -> [a] -> [a]
: [Char]
w [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
r
data SnocBuilder a = SnocBuilder {-# UNPACK #-} !Word [a] [a]
{-# INLINE sb #-}
sb :: Word -> [a] -> [a] -> SnocBuilder a
sb :: forall a. Word -> [a] -> [a] -> SnocBuilder a
sb Word
lp [a]
f [a]
r
| Word
lp Word -> Word -> Bool
forall a. Ord a => a -> a -> Bool
< Word
255 Bool -> Bool -> Bool
|| (Word
lp Word -> Word -> Word
forall a. Bits a => a -> a -> a
.&. (Word
lp Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
1)) Word -> Word -> Bool
forall a. Eq a => a -> a -> Bool
/= Word
0 = Word -> [a] -> [a] -> SnocBuilder a
forall a. Word -> [a] -> [a] -> SnocBuilder a
SnocBuilder Word
lp [a]
f [a]
r
| Bool
otherwise = Word -> [a] -> [a] -> SnocBuilder a
forall a. Word -> [a] -> [a] -> SnocBuilder a
SnocBuilder Word
lp ([a]
f [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a] -> [a]
forall a. [a] -> [a]
reverse [a]
r) []
emptySB :: SnocBuilder a
emptySB :: forall a. SnocBuilder a
emptySB = Word -> [a] -> [a] -> SnocBuilder a
forall a. Word -> [a] -> [a] -> SnocBuilder a
SnocBuilder Word
0 [] []
snocSB :: SnocBuilder a -> a -> SnocBuilder a
snocSB :: forall a. SnocBuilder a -> a -> SnocBuilder a
snocSB (SnocBuilder Word
lp [a]
f [a]
r) a
x = Word -> [a] -> [a] -> SnocBuilder a
forall a. Word -> [a] -> [a] -> SnocBuilder a
sb (Word
lp Word -> Word -> Word
forall a. Num a => a -> a -> a
+ Word
1) [a]
f (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:[a]
r)
toListSB :: SnocBuilder a -> [a]
toListSB :: forall a. SnocBuilder a -> [a]
toListSB (SnocBuilder Word
_ [a]
f [a]
r) = [a]
f [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a] -> [a]
forall a. [a] -> [a]
reverse [a]
r