{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveLift #-}
module Dhall.Set (
Set(..)
, toList
, toAscList
, toSet
, toSeq
, fromList
, fromSet
, append
, empty
, difference
, sort
, isSorted
, null
, size
) where
import Control.DeepSeq (NFData)
import Data.Data (Data)
import Data.List (foldl')
import Data.Sequence (Seq, (|>))
import GHC.Generics (Generic)
import Instances.TH.Lift ()
import Language.Haskell.TH.Syntax (Lift)
import Prelude hiding (null)
import qualified Data.Foldable
import qualified Data.Sequence
import qualified Data.Set
data Set a = Set (Data.Set.Set a) (Seq a)
deriving (forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Set a) x -> Set a
forall a x. Set a -> Rep (Set a) x
$cto :: forall a x. Rep (Set a) x -> Set a
$cfrom :: forall a x. Set a -> Rep (Set a) x
Generic, Int -> Set a -> ShowS
forall a. Show a => Int -> Set a -> ShowS
forall a. Show a => [Set a] -> ShowS
forall a. Show a => Set a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Set a] -> ShowS
$cshowList :: forall a. Show a => [Set a] -> ShowS
show :: Set a -> String
$cshow :: forall a. Show a => Set a -> String
showsPrec :: Int -> Set a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Set a -> ShowS
Show, Set a -> DataType
Set a -> Constr
forall {a}. (Data a, Ord a) => Typeable (Set a)
forall a. (Data a, Ord a) => Set a -> DataType
forall a. (Data a, Ord a) => Set a -> Constr
forall a.
(Data a, Ord a) =>
(forall b. Data b => b -> b) -> Set a -> Set a
forall a u.
(Data a, Ord a) =>
Int -> (forall d. Data d => d -> u) -> Set a -> u
forall a u.
(Data a, Ord a) =>
(forall d. Data d => d -> u) -> Set a -> [u]
forall a r r'.
(Data a, Ord a) =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Set a -> r
forall a r r'.
(Data a, Ord a) =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Set a -> r
forall a (m :: * -> *).
(Data a, Ord a, Monad m) =>
(forall d. Data d => d -> m d) -> Set a -> m (Set a)
forall a (m :: * -> *).
(Data a, Ord a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Set a -> m (Set a)
forall a (c :: * -> *).
(Data a, Ord a) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Set a)
forall a (c :: * -> *).
(Data a, Ord a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Set a -> c (Set a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Ord a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Set a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Ord a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Set a))
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Set a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Set a -> c (Set a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Set a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Set a -> m (Set a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, Ord a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Set a -> m (Set a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Set a -> m (Set a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, Ord a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> Set a -> m (Set a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Set a -> m (Set a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Ord a, Monad m) =>
(forall d. Data d => d -> m d) -> Set a -> m (Set a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Set a -> u
$cgmapQi :: forall a u.
(Data a, Ord a) =>
Int -> (forall d. Data d => d -> u) -> Set a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Set a -> [u]
$cgmapQ :: forall a u.
(Data a, Ord a) =>
(forall d. Data d => d -> u) -> Set a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Set a -> r
$cgmapQr :: forall a r r'.
(Data a, Ord a) =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Set a -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Set a -> r
$cgmapQl :: forall a r r'.
(Data a, Ord a) =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Set a -> r
gmapT :: (forall b. Data b => b -> b) -> Set a -> Set a
$cgmapT :: forall a.
(Data a, Ord a) =>
(forall b. Data b => b -> b) -> Set a -> Set a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Set a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Ord a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Set a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Set a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Ord a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Set a))
dataTypeOf :: Set a -> DataType
$cdataTypeOf :: forall a. (Data a, Ord a) => Set a -> DataType
toConstr :: Set a -> Constr
$ctoConstr :: forall a. (Data a, Ord a) => Set a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Set a)
$cgunfold :: forall a (c :: * -> *).
(Data a, Ord a) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Set a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Set a -> c (Set a)
$cgfoldl :: forall a (c :: * -> *).
(Data a, Ord a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Set a -> c (Set a)
Data, forall a. NFData a => Set a -> ()
forall a. (a -> ()) -> NFData a
rnf :: Set a -> ()
$crnf :: forall a. NFData a => Set a -> ()
NFData, forall a (m :: * -> *). (Lift a, Quote m) => Set a -> m Exp
forall a (m :: * -> *).
(Lift a, Quote m) =>
Set a -> Code m (Set a)
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => Set a -> m Exp
forall (m :: * -> *). Quote m => Set a -> Code m (Set a)
liftTyped :: forall (m :: * -> *). Quote m => Set a -> Code m (Set a)
$cliftTyped :: forall a (m :: * -> *).
(Lift a, Quote m) =>
Set a -> Code m (Set a)
lift :: forall (m :: * -> *). Quote m => Set a -> m Exp
$clift :: forall a (m :: * -> *). (Lift a, Quote m) => Set a -> m Exp
Lift)
instance Eq a => Eq (Set a) where
(Set Set a
_ Seq a
x) == :: Set a -> Set a -> Bool
== (Set Set a
_ Seq a
y) = Seq a
x forall a. Eq a => a -> a -> Bool
== Seq a
y
{-# INLINABLE (==) #-}
instance Ord a => Ord (Set a) where
compare :: Set a -> Set a -> Ordering
compare (Set Set a
_ Seq a
x) (Set Set a
_ Seq a
y) = forall a. Ord a => a -> a -> Ordering
compare Seq a
x Seq a
y
{-# INLINABLE compare #-}
instance Foldable Set where
foldMap :: forall m a. Monoid m => (a -> m) -> Set a -> m
foldMap a -> m
f (Set Set a
_ Seq a
x) = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f Seq a
x
{-# INLINABLE foldMap #-}
toList :: forall a. Set a -> [a]
toList = forall a. Set a -> [a]
Dhall.Set.toList
{-# INLINABLE toList #-}
null :: forall a. Set a -> Bool
null = forall a. Set a -> Bool
Dhall.Set.null
{-# INLINABLE null #-}
length :: forall a. Set a -> Int
length = forall a. Set a -> Int
Dhall.Set.size
{-# INLINABLE length #-}
toSet :: Set a -> Data.Set.Set a
toSet :: forall a. Set a -> Set a
toSet (Set Set a
s Seq a
_) = Set a
s
toSeq :: Set a -> Seq a
toSeq :: forall a. Set a -> Seq a
toSeq (Set Set a
_ Seq a
xs) = Seq a
xs
toList :: Set a -> [a]
toList :: forall a. Set a -> [a]
toList (Set Set a
_ Seq a
xs) = forall (t :: * -> *) a. Foldable t => t a -> [a]
Data.Foldable.toList Seq a
xs
toAscList :: Set a -> [a]
toAscList :: forall a. Set a -> [a]
toAscList (Set Set a
s Seq a
_) = forall a. Set a -> [a]
Data.Set.toAscList Set a
s
fromList :: Ord a => [a] -> Set a
fromList :: forall a. Ord a => [a] -> Set a
fromList = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a. Ord a => a -> Set a -> Set a
append) forall a. Set a
empty
fromSet :: Data.Set.Set a -> Set a
fromSet :: forall a. Set a -> Set a
fromSet Set a
s = forall a. Set a -> Seq a -> Set a
Set Set a
s (forall a. [a] -> Seq a
Data.Sequence.fromList (forall a. Set a -> [a]
Data.Set.elems Set a
s))
append :: Ord a => a -> Set a -> Set a
append :: forall a. Ord a => a -> Set a -> Set a
append a
x os :: Set a
os@(Set Set a
s Seq a
xs)
| forall a. Ord a => a -> Set a -> Bool
Data.Set.member a
x Set a
s = Set a
os
| Bool
otherwise = forall a. Set a -> Seq a -> Set a
Set (forall a. Ord a => a -> Set a -> Set a
Data.Set.insert a
x Set a
s) (Seq a
xs forall a. Seq a -> a -> Seq a
|> a
x)
empty :: Set a
empty :: forall a. Set a
empty = forall a. Set a -> Seq a -> Set a
Set forall a. Set a
Data.Set.empty forall a. Seq a
Data.Sequence.empty
difference :: Ord a => Set a -> Set a -> [a]
difference :: forall a. Ord a => Set a -> Set a -> [a]
difference Set a
os (Set Set a
s Seq a
_) =
forall a. (a -> Bool) -> [a] -> [a]
filter (\ a
x -> Bool -> Bool
not (forall a. Ord a => a -> Set a -> Bool
Data.Set.member a
x Set a
s)) (forall a. Set a -> [a]
toList Set a
os)
sort :: Ord a => Set a -> Set a
sort :: forall a. Ord a => Set a -> Set a
sort (Set Set a
s Seq a
_) = forall a. Set a -> Seq a -> Set a
Set Set a
s (forall a. [a] -> Seq a
Data.Sequence.fromList (forall a. Set a -> [a]
Data.Set.toList Set a
s))
isSorted :: Ord a => Set a -> Bool
isSorted :: forall a. Ord a => Set a -> Bool
isSorted Set a
s = forall a. Set a -> [a]
toList Set a
s forall a. Eq a => a -> a -> Bool
== forall a. Set a -> [a]
Data.Set.toList (forall a. Set a -> Set a
toSet Set a
s)
null :: Set a -> Bool
null :: forall a. Set a -> Bool
null (Set Set a
s Seq a
_) = forall a. Set a -> Bool
Data.Set.null Set a
s
size :: Set a -> Int
size :: forall a. Set a -> Int
size (Set Set a
s Seq a
_) = forall a. Set a -> Int
Data.Set.size Set a
s