{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE ScopedTypeVariables #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  Language.Haskell.TH.Desugar.OSet
-- Copyright   :  (C) 2016-2018 Daniel Wagner, 2019 Ryan Scott
-- License     :  BSD-style (see LICENSE)
-- Maintainer  :  Ryan Scott
-- Stability   :  experimental
-- Portability :  non-portable
--
-- An 'OSet' behaves much like a 'S.Set', with all the same asymptotics, but
-- also remembers the order that values were inserted.
--
-- This module offers a simplified version of the "Data.Set.Ordered" API
-- that assumes left-biased indices everywhere.
--
----------------------------------------------------------------------------
module Language.Haskell.TH.Desugar.OSet
    ( OSet
    -- * Trivial sets
    , empty, singleton
    -- * Insertion
    , insertPre, insertPost, union
    -- * Query
    , null, size, member, notMember
    -- * Deletion
    , delete, filter, (\\), intersection
    -- * Indexing
    , Index, lookupIndex, lookupAt
    -- * List conversions
    , fromList, toAscList
    -- * 'Set' conversion
    , toSet
    ) where

import Data.Coerce
import Data.Data
import qualified Data.Set as S (Set)
import Data.Set.Ordered (Bias(..), Index, L)
import qualified Data.Set.Ordered as OS
import Language.Haskell.TH.Desugar.OMap ()
import Prelude hiding (filter, null)

#if !(MIN_VERSION_base(4,8,0))
import Data.Foldable (Foldable)
import Data.Monoid (Monoid)
#endif

#if !(MIN_VERSION_base(4,11,0))
import Data.Semigroup (Semigroup(..))
#endif

-- | An ordered set whose 'insertPre', 'insertPost', 'intersection', and 'union'
-- operations are biased towards leftmost indices when when breaking ties
-- between keys.
newtype OSet a = OSet (Bias L (OS.OSet a))
  deriving (Typeable (OSet a)
DataType
Constr
Typeable (OSet a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> OSet a -> c (OSet a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (OSet a))
-> (OSet a -> Constr)
-> (OSet a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (OSet a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (OSet a)))
-> ((forall b. Data b => b -> b) -> OSet a -> OSet a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> OSet a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> OSet a -> r)
-> (forall u. (forall d. Data d => d -> u) -> OSet a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> OSet a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> OSet a -> m (OSet a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OSet a -> m (OSet a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OSet a -> m (OSet a))
-> Data (OSet a)
OSet a -> DataType
OSet a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (OSet a))
(forall b. Data b => b -> b) -> OSet a -> OSet a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OSet a -> c (OSet a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (OSet a)
forall a. (Data a, Ord a) => Typeable (OSet a)
forall a. (Data a, Ord a) => OSet a -> DataType
forall a. (Data a, Ord a) => OSet a -> Constr
forall a.
(Data a, Ord a) =>
(forall b. Data b => b -> b) -> OSet a -> OSet a
forall a u.
(Data a, Ord a) =>
Int -> (forall d. Data d => d -> u) -> OSet a -> u
forall a u.
(Data a, Ord a) =>
(forall d. Data d => d -> u) -> OSet a -> [u]
forall a r r'.
(Data a, Ord a) =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> OSet a -> r
forall a r r'.
(Data a, Ord a) =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> OSet a -> r
forall a (m :: * -> *).
(Data a, Ord a, Monad m) =>
(forall d. Data d => d -> m d) -> OSet a -> m (OSet a)
forall a (m :: * -> *).
(Data a, Ord a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> OSet a -> m (OSet 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 (OSet a)
forall a (c :: * -> *).
(Data a, Ord a) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OSet a -> c (OSet a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Ord a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (OSet a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Ord a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (OSet 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 u. Int -> (forall d. Data d => d -> u) -> OSet a -> u
forall u. (forall d. Data d => d -> u) -> OSet a -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> OSet a -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> OSet a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OSet a -> m (OSet a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OSet a -> m (OSet a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (OSet a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OSet a -> c (OSet a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (OSet a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (OSet a))
$cOSet :: Constr
$tOSet :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> OSet a -> m (OSet a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, Ord a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> OSet a -> m (OSet a)
gmapMp :: (forall d. Data d => d -> m d) -> OSet a -> m (OSet a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, Ord a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> OSet a -> m (OSet a)
gmapM :: (forall d. Data d => d -> m d) -> OSet a -> m (OSet a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Ord a, Monad m) =>
(forall d. Data d => d -> m d) -> OSet a -> m (OSet a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> OSet a -> u
$cgmapQi :: forall a u.
(Data a, Ord a) =>
Int -> (forall d. Data d => d -> u) -> OSet a -> u
gmapQ :: (forall d. Data d => d -> u) -> OSet a -> [u]
$cgmapQ :: forall a u.
(Data a, Ord a) =>
(forall d. Data d => d -> u) -> OSet a -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> OSet a -> r
$cgmapQr :: forall a r r'.
(Data a, Ord a) =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> OSet a -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> OSet a -> r
$cgmapQl :: forall a r r'.
(Data a, Ord a) =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> OSet a -> r
gmapT :: (forall b. Data b => b -> b) -> OSet a -> OSet a
$cgmapT :: forall a.
(Data a, Ord a) =>
(forall b. Data b => b -> b) -> OSet a -> OSet a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (OSet 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 (OSet a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (OSet a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Ord a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (OSet a))
dataTypeOf :: OSet a -> DataType
$cdataTypeOf :: forall a. (Data a, Ord a) => OSet a -> DataType
toConstr :: OSet a -> Constr
$ctoConstr :: forall a. (Data a, Ord a) => OSet a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (OSet 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 (OSet a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OSet a -> c (OSet 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) -> OSet a -> c (OSet a)
$cp1Data :: forall a. (Data a, Ord a) => Typeable (OSet a)
Data, OSet a -> Bool
(a -> m) -> OSet a -> m
(a -> b -> b) -> b -> OSet a -> b
(forall m. Monoid m => OSet m -> m)
-> (forall m a. Monoid m => (a -> m) -> OSet a -> m)
-> (forall m a. Monoid m => (a -> m) -> OSet a -> m)
-> (forall a b. (a -> b -> b) -> b -> OSet a -> b)
-> (forall a b. (a -> b -> b) -> b -> OSet a -> b)
-> (forall b a. (b -> a -> b) -> b -> OSet a -> b)
-> (forall b a. (b -> a -> b) -> b -> OSet a -> b)
-> (forall a. (a -> a -> a) -> OSet a -> a)
-> (forall a. (a -> a -> a) -> OSet a -> a)
-> (forall a. OSet a -> [a])
-> (forall a. OSet a -> Bool)
-> (forall a. OSet a -> Int)
-> (forall a. Eq a => a -> OSet a -> Bool)
-> (forall a. Ord a => OSet a -> a)
-> (forall a. Ord a => OSet a -> a)
-> (forall a. Num a => OSet a -> a)
-> (forall a. Num a => OSet a -> a)
-> Foldable OSet
forall a. Eq a => a -> OSet a -> Bool
forall a. Num a => OSet a -> a
forall a. Ord a => OSet a -> a
forall m. Monoid m => OSet m -> m
forall a. OSet a -> Bool
forall a. OSet a -> Int
forall a. OSet a -> [a]
forall a. (a -> a -> a) -> OSet a -> a
forall m a. Monoid m => (a -> m) -> OSet a -> m
forall b a. (b -> a -> b) -> b -> OSet a -> b
forall a b. (a -> b -> b) -> b -> OSet 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 :: OSet a -> a
$cproduct :: forall a. Num a => OSet a -> a
sum :: OSet a -> a
$csum :: forall a. Num a => OSet a -> a
minimum :: OSet a -> a
$cminimum :: forall a. Ord a => OSet a -> a
maximum :: OSet a -> a
$cmaximum :: forall a. Ord a => OSet a -> a
elem :: a -> OSet a -> Bool
$celem :: forall a. Eq a => a -> OSet a -> Bool
length :: OSet a -> Int
$clength :: forall a. OSet a -> Int
null :: OSet a -> Bool
$cnull :: forall a. OSet a -> Bool
toList :: OSet a -> [a]
$ctoList :: forall a. OSet a -> [a]
foldl1 :: (a -> a -> a) -> OSet a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> OSet a -> a
foldr1 :: (a -> a -> a) -> OSet a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> OSet a -> a
foldl' :: (b -> a -> b) -> b -> OSet a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> OSet a -> b
foldl :: (b -> a -> b) -> b -> OSet a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> OSet a -> b
foldr' :: (a -> b -> b) -> b -> OSet a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> OSet a -> b
foldr :: (a -> b -> b) -> b -> OSet a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> OSet a -> b
foldMap' :: (a -> m) -> OSet a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> OSet a -> m
foldMap :: (a -> m) -> OSet a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> OSet a -> m
fold :: OSet m -> m
$cfold :: forall m. Monoid m => OSet m -> m
Foldable, OSet a -> OSet a -> Bool
(OSet a -> OSet a -> Bool)
-> (OSet a -> OSet a -> Bool) -> Eq (OSet a)
forall a. Eq a => OSet a -> OSet a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OSet a -> OSet a -> Bool
$c/= :: forall a. Eq a => OSet a -> OSet a -> Bool
== :: OSet a -> OSet a -> Bool
$c== :: forall a. Eq a => OSet a -> OSet a -> Bool
Eq, Semigroup (OSet a)
OSet a
Semigroup (OSet a)
-> OSet a
-> (OSet a -> OSet a -> OSet a)
-> ([OSet a] -> OSet a)
-> Monoid (OSet a)
[OSet a] -> OSet a
OSet a -> OSet a -> OSet a
forall a. Ord a => Semigroup (OSet a)
forall a. Ord a => OSet a
forall a. Ord a => [OSet a] -> OSet a
forall a. Ord a => OSet a -> OSet a -> OSet a
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [OSet a] -> OSet a
$cmconcat :: forall a. Ord a => [OSet a] -> OSet a
mappend :: OSet a -> OSet a -> OSet a
$cmappend :: forall a. Ord a => OSet a -> OSet a -> OSet a
mempty :: OSet a
$cmempty :: forall a. Ord a => OSet a
$cp1Monoid :: forall a. Ord a => Semigroup (OSet a)
Monoid, Eq (OSet a)
Eq (OSet a)
-> (OSet a -> OSet a -> Ordering)
-> (OSet a -> OSet a -> Bool)
-> (OSet a -> OSet a -> Bool)
-> (OSet a -> OSet a -> Bool)
-> (OSet a -> OSet a -> Bool)
-> (OSet a -> OSet a -> OSet a)
-> (OSet a -> OSet a -> OSet a)
-> Ord (OSet a)
OSet a -> OSet a -> Bool
OSet a -> OSet a -> Ordering
OSet a -> OSet a -> OSet 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 (OSet a)
forall a. Ord a => OSet a -> OSet a -> Bool
forall a. Ord a => OSet a -> OSet a -> Ordering
forall a. Ord a => OSet a -> OSet a -> OSet a
min :: OSet a -> OSet a -> OSet a
$cmin :: forall a. Ord a => OSet a -> OSet a -> OSet a
max :: OSet a -> OSet a -> OSet a
$cmax :: forall a. Ord a => OSet a -> OSet a -> OSet a
>= :: OSet a -> OSet a -> Bool
$c>= :: forall a. Ord a => OSet a -> OSet a -> Bool
> :: OSet a -> OSet a -> Bool
$c> :: forall a. Ord a => OSet a -> OSet a -> Bool
<= :: OSet a -> OSet a -> Bool
$c<= :: forall a. Ord a => OSet a -> OSet a -> Bool
< :: OSet a -> OSet a -> Bool
$c< :: forall a. Ord a => OSet a -> OSet a -> Bool
compare :: OSet a -> OSet a -> Ordering
$ccompare :: forall a. Ord a => OSet a -> OSet a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (OSet a)
Ord, ReadPrec [OSet a]
ReadPrec (OSet a)
Int -> ReadS (OSet a)
ReadS [OSet a]
(Int -> ReadS (OSet a))
-> ReadS [OSet a]
-> ReadPrec (OSet a)
-> ReadPrec [OSet a]
-> Read (OSet a)
forall a. (Ord a, Read a) => ReadPrec [OSet a]
forall a. (Ord a, Read a) => ReadPrec (OSet a)
forall a. (Ord a, Read a) => Int -> ReadS (OSet a)
forall a. (Ord a, Read a) => ReadS [OSet a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OSet a]
$creadListPrec :: forall a. (Ord a, Read a) => ReadPrec [OSet a]
readPrec :: ReadPrec (OSet a)
$creadPrec :: forall a. (Ord a, Read a) => ReadPrec (OSet a)
readList :: ReadS [OSet a]
$creadList :: forall a. (Ord a, Read a) => ReadS [OSet a]
readsPrec :: Int -> ReadS (OSet a)
$creadsPrec :: forall a. (Ord a, Read a) => Int -> ReadS (OSet a)
Read, Int -> OSet a -> ShowS
[OSet a] -> ShowS
OSet a -> String
(Int -> OSet a -> ShowS)
-> (OSet a -> String) -> ([OSet a] -> ShowS) -> Show (OSet a)
forall a. Show a => Int -> OSet a -> ShowS
forall a. Show a => [OSet a] -> ShowS
forall a. Show a => OSet a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OSet a] -> ShowS
$cshowList :: forall a. Show a => [OSet a] -> ShowS
show :: OSet a -> String
$cshow :: forall a. Show a => OSet a -> String
showsPrec :: Int -> OSet a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> OSet a -> ShowS
Show, Typeable)

instance Ord a => Semigroup (OSet a) where
  <> :: OSet a -> OSet a -> OSet a
(<>) = OSet a -> OSet a -> OSet a
forall a. Ord a => OSet a -> OSet a -> OSet a
union

empty :: forall a. OSet a
empty :: OSet a
empty = OSet a -> OSet a
coerce (OSet a
forall a. OSet a
OS.empty :: OS.OSet a)

singleton :: a -> OSet a
singleton :: a -> OSet a
singleton a
a = OSet a -> OSet a
coerce (a -> OSet a
forall a. a -> OSet a
OS.singleton a
a)

-- | The element's index will be lower than the indices of the elements in the
-- 'OSet'.
insertPre :: Ord a => a -> OSet a -> OSet a
insertPre :: a -> OSet a -> OSet a
insertPre a
a = (OSet a -> OSet a) -> OSet a -> OSet a
coerce (a
a a -> OSet a -> OSet a
forall a. Ord a => a -> OSet a -> OSet a
OS.|<)

-- | The element's index will be higher than the indices of the elements in the
-- 'OSet'.
insertPost :: Ord a => OSet a -> a -> OSet a
insertPost :: OSet a -> a -> OSet a
insertPost OSet a
s a
a = OSet a -> OSet a
coerce (OSet a -> OSet a
coerce OSet a
s OSet a -> a -> OSet a
forall a. Ord a => OSet a -> a -> OSet a
OS.|> a
a)

union :: forall a. Ord a => OSet a -> OSet a -> OSet a
union :: OSet a -> OSet a -> OSet a
union = (OSet a -> OSet a -> OSet a) -> OSet a -> OSet a -> OSet a
coerce (OSet a -> OSet a -> OSet a
forall a. Ord a => OSet a -> OSet a -> OSet a
(OS.|<>) :: OS.OSet a -> OS.OSet a -> OS.OSet a)

null :: forall a. OSet a -> Bool
null :: OSet a -> Bool
null = (OSet a -> Bool) -> OSet a -> Bool
coerce (OSet a -> Bool
forall a. OSet a -> Bool
OS.null :: OS.OSet a -> Bool)

size :: forall a. OSet a -> Int
size :: OSet a -> Int
size = (OSet a -> Int) -> OSet a -> Int
coerce (OSet a -> Int
forall a. OSet a -> Int
OS.size :: OS.OSet a -> Int)

member, notMember :: Ord a => a -> OSet a -> Bool
member :: a -> OSet a -> Bool
member    a
a = (OSet a -> Bool) -> OSet a -> Bool
coerce (a -> OSet a -> Bool
forall a. Ord a => a -> OSet a -> Bool
OS.member a
a)
notMember :: a -> OSet a -> Bool
notMember a
a = (OSet a -> Bool) -> OSet a -> Bool
coerce (a -> OSet a -> Bool
forall a. Ord a => a -> OSet a -> Bool
OS.notMember a
a)

delete :: Ord a => a -> OSet a -> OSet a
delete :: a -> OSet a -> OSet a
delete a
a = (OSet a -> OSet a) -> OSet a -> OSet a
coerce (a -> OSet a -> OSet a
forall a. Ord a => a -> OSet a -> OSet a
OS.delete a
a)

filter :: Ord a => (a -> Bool) -> OSet a -> OSet a
filter :: (a -> Bool) -> OSet a -> OSet a
filter a -> Bool
f = (OSet a -> OSet a) -> OSet a -> OSet a
coerce ((a -> Bool) -> OSet a -> OSet a
forall a. Ord a => (a -> Bool) -> OSet a -> OSet a
OS.filter a -> Bool
f)

(\\) :: forall a. Ord a => OSet a -> OSet a -> OSet a
\\ :: OSet a -> OSet a -> OSet a
(\\) = (OSet a -> OSet a -> OSet a) -> OSet a -> OSet a -> OSet a
coerce (OSet a -> OSet a -> OSet a
forall a. Ord a => OSet a -> OSet a -> OSet a
(OS.\\) :: OS.OSet a -> OS.OSet a -> OS.OSet a)

intersection :: forall a. Ord a => OSet a -> OSet a -> OSet a
intersection :: OSet a -> OSet a -> OSet a
intersection = (OSet a -> OSet a -> OSet a) -> OSet a -> OSet a -> OSet a
coerce (OSet a -> OSet a -> OSet a
forall a. Ord a => OSet a -> OSet a -> OSet a
(OS.|/\) :: OS.OSet a -> OS.OSet a -> OS.OSet a)

lookupIndex :: Ord a => a -> OSet a -> Maybe Index
lookupIndex :: a -> OSet a -> Maybe Int
lookupIndex a
a = (OSet a -> Maybe Int) -> OSet a -> Maybe Int
coerce (a -> OSet a -> Maybe Int
forall a. Ord a => a -> OSet a -> Maybe Int
OS.findIndex a
a)

lookupAt :: forall a. Index -> OSet a -> Maybe a
lookupAt :: Int -> OSet a -> Maybe a
lookupAt Int
i OSet a
s = Maybe a -> Maybe a
coerce (OSet a -> Int -> Maybe a
forall a. OSet a -> Int -> Maybe a
OS.elemAt (OSet a -> OSet a
coerce OSet a
s) Int
i :: Maybe a)

fromList :: Ord a => [a] -> OSet a
fromList :: [a] -> OSet a
fromList [a]
l = OSet a -> OSet a
coerce ([a] -> OSet a
forall a. Ord a => [a] -> OSet a
OS.fromList [a]
l)

toAscList :: forall a. OSet a -> [a]
toAscList :: OSet a -> [a]
toAscList = (OSet a -> [a]) -> OSet a -> [a]
coerce (OSet a -> [a]
forall a. OSet a -> [a]
OS.toAscList :: OS.OSet a -> [a])

toSet :: forall a. OSet a -> S.Set a
toSet :: OSet a -> Set a
toSet = (OSet a -> Set a) -> OSet a -> Set a
coerce (OSet a -> Set a
forall a. OSet a -> Set a
OS.toSet :: OS.OSet a -> S.Set a)