{-# LANGUAGE TypeFamilies #-}
module BNFC.Utils.List2
( module BNFC.Utils.List2
, module Reexport
) where
import Prelude
( Eq, Ord, Show, Functor, Foldable, Traversable
, (.), ($), (++)
, Bool
, seq
, undefined
)
import Control.DeepSeq
import qualified Data.List as List
import qualified Data.List.NonEmpty as List1
import Data.List.NonEmpty ( pattern (:|) )
import Data.Semigroup ( Semigroup(..) )
import GHC.Exts ( IsList(..) )
import qualified GHC.Exts as Reexport ( toList )
type List1 = List1.NonEmpty
data List2 a = List2 a a [a]
deriving (List2 a -> List2 a -> Bool
(List2 a -> List2 a -> Bool)
-> (List2 a -> List2 a -> Bool) -> Eq (List2 a)
forall a. Eq a => List2 a -> List2 a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: List2 a -> List2 a -> Bool
$c/= :: forall a. Eq a => List2 a -> List2 a -> Bool
== :: List2 a -> List2 a -> Bool
$c== :: forall a. Eq a => List2 a -> List2 a -> Bool
Eq, Eq (List2 a)
Eq (List2 a)
-> (List2 a -> List2 a -> Ordering)
-> (List2 a -> List2 a -> Bool)
-> (List2 a -> List2 a -> Bool)
-> (List2 a -> List2 a -> Bool)
-> (List2 a -> List2 a -> Bool)
-> (List2 a -> List2 a -> List2 a)
-> (List2 a -> List2 a -> List2 a)
-> Ord (List2 a)
List2 a -> List2 a -> Bool
List2 a -> List2 a -> Ordering
List2 a -> List2 a -> List2 a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (List2 a)
forall a. Ord a => List2 a -> List2 a -> Bool
forall a. Ord a => List2 a -> List2 a -> Ordering
forall a. Ord a => List2 a -> List2 a -> List2 a
min :: List2 a -> List2 a -> List2 a
$cmin :: forall a. Ord a => List2 a -> List2 a -> List2 a
max :: List2 a -> List2 a -> List2 a
$cmax :: forall a. Ord a => List2 a -> List2 a -> List2 a
>= :: List2 a -> List2 a -> Bool
$c>= :: forall a. Ord a => List2 a -> List2 a -> Bool
> :: List2 a -> List2 a -> Bool
$c> :: forall a. Ord a => List2 a -> List2 a -> Bool
<= :: List2 a -> List2 a -> Bool
$c<= :: forall a. Ord a => List2 a -> List2 a -> Bool
< :: List2 a -> List2 a -> Bool
$c< :: forall a. Ord a => List2 a -> List2 a -> Bool
compare :: List2 a -> List2 a -> Ordering
$ccompare :: forall a. Ord a => List2 a -> List2 a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (List2 a)
Ord, Int -> List2 a -> ShowS
[List2 a] -> ShowS
List2 a -> String
(Int -> List2 a -> ShowS)
-> (List2 a -> String) -> ([List2 a] -> ShowS) -> Show (List2 a)
forall a. Show a => Int -> List2 a -> ShowS
forall a. Show a => [List2 a] -> ShowS
forall a. Show a => List2 a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [List2 a] -> ShowS
$cshowList :: forall a. Show a => [List2 a] -> ShowS
show :: List2 a -> String
$cshow :: forall a. Show a => List2 a -> String
showsPrec :: Int -> List2 a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> List2 a -> ShowS
Show, a -> List2 b -> List2 a
(a -> b) -> List2 a -> List2 b
(forall a b. (a -> b) -> List2 a -> List2 b)
-> (forall a b. a -> List2 b -> List2 a) -> Functor List2
forall a b. a -> List2 b -> List2 a
forall a b. (a -> b) -> List2 a -> List2 b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> List2 b -> List2 a
$c<$ :: forall a b. a -> List2 b -> List2 a
fmap :: (a -> b) -> List2 a -> List2 b
$cfmap :: forall a b. (a -> b) -> List2 a -> List2 b
Functor, List2 a -> Bool
(a -> m) -> List2 a -> m
(a -> b -> b) -> b -> List2 a -> b
(forall m. Monoid m => List2 m -> m)
-> (forall m a. Monoid m => (a -> m) -> List2 a -> m)
-> (forall m a. Monoid m => (a -> m) -> List2 a -> m)
-> (forall a b. (a -> b -> b) -> b -> List2 a -> b)
-> (forall a b. (a -> b -> b) -> b -> List2 a -> b)
-> (forall b a. (b -> a -> b) -> b -> List2 a -> b)
-> (forall b a. (b -> a -> b) -> b -> List2 a -> b)
-> (forall a. (a -> a -> a) -> List2 a -> a)
-> (forall a. (a -> a -> a) -> List2 a -> a)
-> (forall a. List2 a -> [a])
-> (forall a. List2 a -> Bool)
-> (forall a. List2 a -> Int)
-> (forall a. Eq a => a -> List2 a -> Bool)
-> (forall a. Ord a => List2 a -> a)
-> (forall a. Ord a => List2 a -> a)
-> (forall a. Num a => List2 a -> a)
-> (forall a. Num a => List2 a -> a)
-> Foldable List2
forall a. Eq a => a -> List2 a -> Bool
forall a. Num a => List2 a -> a
forall a. Ord a => List2 a -> a
forall m. Monoid m => List2 m -> m
forall a. List2 a -> Bool
forall a. List2 a -> Int
forall a. List2 a -> [a]
forall a. (a -> a -> a) -> List2 a -> a
forall m a. Monoid m => (a -> m) -> List2 a -> m
forall b a. (b -> a -> b) -> b -> List2 a -> b
forall a b. (a -> b -> b) -> b -> List2 a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: List2 a -> a
$cproduct :: forall a. Num a => List2 a -> a
sum :: List2 a -> a
$csum :: forall a. Num a => List2 a -> a
minimum :: List2 a -> a
$cminimum :: forall a. Ord a => List2 a -> a
maximum :: List2 a -> a
$cmaximum :: forall a. Ord a => List2 a -> a
elem :: a -> List2 a -> Bool
$celem :: forall a. Eq a => a -> List2 a -> Bool
length :: List2 a -> Int
$clength :: forall a. List2 a -> Int
null :: List2 a -> Bool
$cnull :: forall a. List2 a -> Bool
toList :: List2 a -> [a]
$ctoList :: forall a. List2 a -> [a]
foldl1 :: (a -> a -> a) -> List2 a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> List2 a -> a
foldr1 :: (a -> a -> a) -> List2 a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> List2 a -> a
foldl' :: (b -> a -> b) -> b -> List2 a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> List2 a -> b
foldl :: (b -> a -> b) -> b -> List2 a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> List2 a -> b
foldr' :: (a -> b -> b) -> b -> List2 a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> List2 a -> b
foldr :: (a -> b -> b) -> b -> List2 a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> List2 a -> b
foldMap' :: (a -> m) -> List2 a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> List2 a -> m
foldMap :: (a -> m) -> List2 a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> List2 a -> m
fold :: List2 m -> m
$cfold :: forall m. Monoid m => List2 m -> m
Foldable, Functor List2
Foldable List2
Functor List2
-> Foldable List2
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> List2 a -> f (List2 b))
-> (forall (f :: * -> *) a.
Applicative f =>
List2 (f a) -> f (List2 a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> List2 a -> m (List2 b))
-> (forall (m :: * -> *) a. Monad m => List2 (m a) -> m (List2 a))
-> Traversable List2
(a -> f b) -> List2 a -> f (List2 b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => List2 (m a) -> m (List2 a)
forall (f :: * -> *) a. Applicative f => List2 (f a) -> f (List2 a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> List2 a -> m (List2 b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> List2 a -> f (List2 b)
sequence :: List2 (m a) -> m (List2 a)
$csequence :: forall (m :: * -> *) a. Monad m => List2 (m a) -> m (List2 a)
mapM :: (a -> m b) -> List2 a -> m (List2 b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> List2 a -> m (List2 b)
sequenceA :: List2 (f a) -> f (List2 a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => List2 (f a) -> f (List2 a)
traverse :: (a -> f b) -> List2 a -> f (List2 b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> List2 a -> f (List2 b)
$cp2Traversable :: Foldable List2
$cp1Traversable :: Functor List2
Traversable)
instance Semigroup (List2 a) where
List2 a
a1 a
a2 [a]
as <> :: List2 a -> List2 a -> List2 a
<> List2 a
bs = a -> a -> [a] -> List2 a
forall a. a -> a -> [a] -> List2 a
List2 a
a1 a
a2 ([a] -> List2 a) -> [a] -> List2 a
forall a b. (a -> b) -> a -> b
$ [a]
as [a] -> [a] -> [a]
forall a. Semigroup a => a -> a -> a
<> List2 a -> [Item (List2 a)]
forall l. IsList l => l -> [Item l]
toList List2 a
bs
cons :: a -> List2 a -> List2 a
cons :: a -> List2 a -> List2 a
cons a
a0 (List2 a
a1 a
a2 [a]
as) = a -> a -> [a] -> List2 a
forall a. a -> a -> [a] -> List2 a
List2 a
a0 a
a1 (a
a2 a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
as)
snoc :: List2 a -> a -> List2 a
snoc :: List2 a -> a -> List2 a
snoc (List2 a
a1 a
a2 [a]
as) a
b = a -> a -> [a] -> List2 a
forall a. a -> a -> [a] -> List2 a
List2 a
a1 a
a2 ([a]
as [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ [a
b])
head :: List2 a -> a
head :: List2 a -> a
head (List2 a
a a
_ [a]
_) = a
a
tail :: List2 a -> [a]
tail :: List2 a -> [a]
tail (List2 a
_ a
b [a]
cs) = a
b a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
cs
tail1 :: List2 a -> List1 a
tail1 :: List2 a -> List1 a
tail1 (List2 a
_ a
b [a]
cs) = a
b a -> [a] -> List1 a
forall a. a -> [a] -> NonEmpty a
:| [a]
cs
instance IsList (List2 a) where
type Item (List2 a) = a
fromList :: [a] -> List2 a
fromList :: [a] -> List2 a
fromList (a
a : a
b : [a]
cs) = a -> a -> [a] -> List2 a
forall a. a -> a -> [a] -> List2 a
List2 a
a a
b [a]
cs
fromList [a]
_ = List2 a
forall a. HasCallStack => a
undefined
toList :: List2 a -> [a]
toList :: List2 a -> [a]
toList (List2 a
a a
b [a]
cs) = a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
b a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
cs
toList1 :: List2 a -> List1 a
toList1 :: List2 a -> List1 a
toList1 (List2 a
a a
b [a]
cs) = a
a a -> [a] -> List1 a
forall a. a -> [a] -> NonEmpty a
:| a
b a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
cs
fromList :: [a] -> List2 a
fromList :: [a] -> List2 a
fromList (a
a : a
b : [a]
cs) = a -> a -> [a] -> List2 a
forall a. a -> a -> [a] -> List2 a
List2 a
a a
b [a]
cs
fromList [a]
_ = List2 a
forall a. HasCallStack => a
undefined
fromList1 :: List1 a -> List2 a
fromList1 :: List1 a -> List2 a
fromList1 (a
a :| a
b : [a]
cs) = a -> a -> [a] -> List2 a
forall a. a -> a -> [a] -> List2 a
List2 a
a a
b [a]
cs
fromList1 List1 a
_ = List2 a
forall a. HasCallStack => a
undefined
break :: (a -> Bool) -> List2 a -> ([a],[a])
break :: (a -> Bool) -> List2 a -> ([a], [a])
break a -> Bool
p = (a -> Bool) -> [a] -> ([a], [a])
forall a. (a -> Bool) -> [a] -> ([a], [a])
List.break a -> Bool
p ([a] -> ([a], [a])) -> (List2 a -> [a]) -> List2 a -> ([a], [a])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List2 a -> [a]
forall l. IsList l => l -> [Item l]
toList
instance NFData a => NFData (List2 a) where
rnf :: List2 a -> ()
rnf (List2 a
a a
b [a]
cs) = a -> ()
forall a. NFData a => a -> ()
rnf a
a () -> () -> ()
`seq` a -> ()
forall a. NFData a => a -> ()
rnf a
b () -> () -> ()
`seq` [a] -> ()
forall a. NFData a => a -> ()
rnf [a]
cs