{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnicodeSyntax #-}
module Data.Enum.Set
( AsEnumSet(..)
, EnumSet
, empty
, singleton
, fromFoldable
, insert
, delete
, member
, notMember
, null
, size
, isSubsetOf
, union
, difference
, (\\)
, symmetricDifference
, intersection
, filter
, partition
, map
, foldl, foldl', foldr, foldr'
, foldl1, foldl1', foldr1, foldr1'
, foldMap
, traverse
, any
, all
, minimum
, maximum
, deleteMin
, deleteMax
, minView
, maxView
, toList
, fromRaw
, toRaw
) where
import Prelude hiding (all, any, filter, foldl, foldl1, foldMap, foldr, foldr1, map, maximum, minimum, null, traverse)
import Data.Bits
import qualified Data.Enum.Set.Base as E
class (Enum a, FiniteBits (EnumSetRep a), Num (EnumSetRep a)) => AsEnumSet a where
type EnumSetRep a
type EnumSetRep a = Word
type EnumSet a = E.EnumSet (EnumSetRep a) a
empty :: ∀ a. AsEnumSet a => EnumSet a
empty :: forall a. AsEnumSet a => EnumSet a
empty = forall {k} w (a :: k). Bits w => EnumSet w a
E.empty
{-# INLINE empty #-}
singleton :: ∀ a. AsEnumSet a => a -> EnumSet a
singleton :: forall a. AsEnumSet a => a -> EnumSet a
singleton = forall w a. (Bits w, Enum a) => a -> EnumSet w a
E.singleton
{-# INLINE singleton #-}
fromFoldable :: ∀ f a. (Foldable f, AsEnumSet a) => f a -> EnumSet a
fromFoldable :: forall (f :: * -> *) a.
(Foldable f, AsEnumSet a) =>
f a -> EnumSet a
fromFoldable = forall (f :: * -> *) w a.
(Foldable f, Bits w, Enum a) =>
f a -> EnumSet w a
E.fromFoldable
{-# INLINE fromFoldable #-}
insert :: ∀ a. AsEnumSet a => a -> EnumSet a -> EnumSet a
insert :: forall a. AsEnumSet a => a -> EnumSet a -> EnumSet a
insert = forall w a. (Bits w, Enum a) => a -> EnumSet w a -> EnumSet w a
E.insert
{-# INLINE insert #-}
delete :: ∀ a. AsEnumSet a => a -> EnumSet a -> EnumSet a
delete :: forall a. AsEnumSet a => a -> EnumSet a -> EnumSet a
delete = forall w a. (Bits w, Enum a) => a -> EnumSet w a -> EnumSet w a
E.delete
{-# INLINE delete #-}
member :: ∀ a. AsEnumSet a => a -> EnumSet a -> Bool
member :: forall a. AsEnumSet a => a -> EnumSet a -> Bool
member = forall w a. (Bits w, Enum a) => a -> EnumSet w a -> Bool
E.member
{-# INLINE member #-}
notMember :: ∀ a. AsEnumSet a => a -> EnumSet a -> Bool
notMember :: forall a. AsEnumSet a => a -> EnumSet a -> Bool
notMember = forall w a. (Bits w, Enum a) => a -> EnumSet w a -> Bool
E.notMember
{-# INLINE notMember #-}
null :: ∀ a. AsEnumSet a => EnumSet a -> Bool
null :: forall a. AsEnumSet a => EnumSet a -> Bool
null = forall {k} w (a :: k). Bits w => EnumSet w a -> Bool
E.null
{-# INLINE null #-}
size :: ∀ a. AsEnumSet a => EnumSet a -> Int
size :: forall a. AsEnumSet a => EnumSet a -> Int
size = forall {k} w (a :: k). (Bits w, Num w) => EnumSet w a -> Int
E.size
{-# INLINE size #-}
isSubsetOf :: ∀ a. AsEnumSet a => EnumSet a -> EnumSet a -> Bool
isSubsetOf :: forall a. AsEnumSet a => EnumSet a -> EnumSet a -> Bool
isSubsetOf = forall {k} w (a :: k). Bits w => EnumSet w a -> EnumSet w a -> Bool
E.isSubsetOf
{-# INLINE isSubsetOf #-}
union :: ∀ a. AsEnumSet a => EnumSet a -> EnumSet a -> EnumSet a
union :: forall a. AsEnumSet a => EnumSet a -> EnumSet a -> EnumSet a
union = forall {k} w (a :: k).
Bits w =>
EnumSet w a -> EnumSet w a -> EnumSet w a
E.union
{-# INLINE union #-}
difference :: ∀ a. AsEnumSet a => EnumSet a -> EnumSet a -> EnumSet a
difference :: forall a. AsEnumSet a => EnumSet a -> EnumSet a -> EnumSet a
difference = forall {k} w (a :: k).
Bits w =>
EnumSet w a -> EnumSet w a -> EnumSet w a
E.difference
{-# INLINE difference #-}
(\\) :: ∀ a. AsEnumSet a => EnumSet a -> EnumSet a -> EnumSet a
\\ :: forall a. AsEnumSet a => EnumSet a -> EnumSet a -> EnumSet a
(\\) = forall {k} w (a :: k).
Bits w =>
EnumSet w a -> EnumSet w a -> EnumSet w a
E.difference
infixl 9 \\
{-# INLINE (\\) #-}
symmetricDifference :: ∀ a. AsEnumSet a => EnumSet a -> EnumSet a -> EnumSet a
symmetricDifference :: forall a. AsEnumSet a => EnumSet a -> EnumSet a -> EnumSet a
symmetricDifference = forall {k} w (a :: k).
Bits w =>
EnumSet w a -> EnumSet w a -> EnumSet w a
E.symmetricDifference
{-# INLINE symmetricDifference #-}
intersection :: ∀ a. AsEnumSet a => EnumSet a -> EnumSet a -> EnumSet a
intersection :: forall a. AsEnumSet a => EnumSet a -> EnumSet a -> EnumSet a
intersection = forall {k} w (a :: k).
Bits w =>
EnumSet w a -> EnumSet w a -> EnumSet w a
E.intersection
{-# INLINE intersection #-}
filter :: ∀ a. AsEnumSet a => (a -> Bool) -> EnumSet a -> EnumSet a
filter :: forall a. AsEnumSet a => (a -> Bool) -> EnumSet a -> EnumSet a
filter = forall w a.
(FiniteBits w, Num w, Enum a) =>
(a -> Bool) -> EnumSet w a -> EnumSet w a
E.filter
{-# INLINE filter #-}
partition :: ∀ a. AsEnumSet a
=> (a -> Bool) -> EnumSet a -> (EnumSet a, EnumSet a)
partition :: forall a.
AsEnumSet a =>
(a -> Bool) -> EnumSet a -> (EnumSet a, EnumSet a)
partition = forall w a.
(FiniteBits w, Num w, Enum a) =>
(a -> Bool) -> EnumSet w a -> (EnumSet w a, EnumSet w a)
E.partition
{-# INLINE partition #-}
map :: ∀ a b. (AsEnumSet a, AsEnumSet b) => (a -> b) -> EnumSet a -> EnumSet b
map :: forall a b.
(AsEnumSet a, AsEnumSet b) =>
(a -> b) -> EnumSet a -> EnumSet b
map = forall v w a b.
(FiniteBits v, FiniteBits w, Num v, Num w, Enum a, Enum b) =>
(a -> b) -> EnumSet v a -> EnumSet w b
E.map'
foldl :: ∀ a b. AsEnumSet a => (b -> a -> b) -> b -> EnumSet a -> b
foldl :: forall a b. AsEnumSet a => (b -> a -> b) -> b -> EnumSet a -> b
foldl = forall w a b.
(FiniteBits w, Num w, Enum a) =>
(b -> a -> b) -> b -> EnumSet w a -> b
E.foldl
{-# INLINE foldl #-}
foldl' :: ∀ a b. AsEnumSet a => (b -> a -> b) -> b -> EnumSet a -> b
foldl' :: forall a b. AsEnumSet a => (b -> a -> b) -> b -> EnumSet a -> b
foldl' = forall w a b.
(FiniteBits w, Num w, Enum a) =>
(b -> a -> b) -> b -> EnumSet w a -> b
E.foldl'
{-# INLINE foldl' #-}
foldr :: ∀ a b. AsEnumSet a => (a -> b -> b) -> b -> EnumSet a -> b
foldr :: forall a b. AsEnumSet a => (a -> b -> b) -> b -> EnumSet a -> b
foldr = forall w a b.
(FiniteBits w, Num w, Enum a) =>
(a -> b -> b) -> b -> EnumSet w a -> b
E.foldr
{-# INLINE foldr #-}
foldr' :: ∀ a b. AsEnumSet a => (a -> b -> b) -> b -> EnumSet a -> b
foldr' :: forall a b. AsEnumSet a => (a -> b -> b) -> b -> EnumSet a -> b
foldr' = forall w a b.
(FiniteBits w, Num w, Enum a) =>
(a -> b -> b) -> b -> EnumSet w a -> b
E.foldr'
{-# INLINE foldr' #-}
foldl1 :: ∀ a. AsEnumSet a => (a -> a -> a) -> EnumSet a -> a
foldl1 :: forall a. AsEnumSet a => (a -> a -> a) -> EnumSet a -> a
foldl1 = forall w a.
(FiniteBits w, Num w, Enum a) =>
(a -> a -> a) -> EnumSet w a -> a
E.foldl1
{-# INLINE foldl1 #-}
foldl1' :: ∀ a. AsEnumSet a => (a -> a -> a) -> EnumSet a -> a
foldl1' :: forall a. AsEnumSet a => (a -> a -> a) -> EnumSet a -> a
foldl1' = forall w a.
(FiniteBits w, Num w, Enum a) =>
(a -> a -> a) -> EnumSet w a -> a
E.foldl1'
{-# INLINE foldl1' #-}
foldr1 :: ∀ a. AsEnumSet a => (a -> a -> a) -> EnumSet a -> a
foldr1 :: forall a. AsEnumSet a => (a -> a -> a) -> EnumSet a -> a
foldr1 = forall w a.
(FiniteBits w, Num w, Enum a) =>
(a -> a -> a) -> EnumSet w a -> a
E.foldr1
{-# INLINE foldr1 #-}
foldr1' :: ∀ a. AsEnumSet a => (a -> a -> a) -> EnumSet a -> a
foldr1' :: forall a. AsEnumSet a => (a -> a -> a) -> EnumSet a -> a
foldr1' = forall w a.
(FiniteBits w, Num w, Enum a) =>
(a -> a -> a) -> EnumSet w a -> a
E.foldr1'
{-# INLINE foldr1' #-}
foldMap :: ∀ m a. (Monoid m, AsEnumSet a) => (a -> m) -> EnumSet a -> m
foldMap :: forall m a. (Monoid m, AsEnumSet a) => (a -> m) -> EnumSet a -> m
foldMap = forall m w a.
(Monoid m, FiniteBits w, Num w, Enum a) =>
(a -> m) -> EnumSet w a -> m
E.foldMap
{-# INLINE foldMap #-}
traverse :: ∀ f a. (Applicative f, AsEnumSet a)
=> (a -> f a) -> EnumSet a -> f (EnumSet a)
traverse :: forall (f :: * -> *) a.
(Applicative f, AsEnumSet a) =>
(a -> f a) -> EnumSet a -> f (EnumSet a)
traverse = forall (f :: * -> *) w a.
(Applicative f, FiniteBits w, Num w, Enum a) =>
(a -> f a) -> EnumSet w a -> f (EnumSet w a)
E.traverse
{-# INLINE traverse #-}
all :: ∀ a. AsEnumSet a => (a -> Bool) -> EnumSet a -> Bool
all :: forall a. AsEnumSet a => (a -> Bool) -> EnumSet a -> Bool
all = forall w a.
(FiniteBits w, Num w, Enum a) =>
(a -> Bool) -> EnumSet w a -> Bool
E.all
{-# INLINE all #-}
any :: ∀ a. AsEnumSet a => (a -> Bool) -> EnumSet a -> Bool
any :: forall a. AsEnumSet a => (a -> Bool) -> EnumSet a -> Bool
any = forall w a.
(FiniteBits w, Num w, Enum a) =>
(a -> Bool) -> EnumSet w a -> Bool
E.any
{-# INLINE any #-}
minimum :: ∀ a. AsEnumSet a => EnumSet a -> a
minimum :: forall a. AsEnumSet a => EnumSet a -> a
minimum = forall w a. (FiniteBits w, Num w, Enum a) => EnumSet w a -> a
E.minimum
{-# INLINE minimum #-}
maximum :: ∀ a. AsEnumSet a => EnumSet a -> a
maximum :: forall a. AsEnumSet a => EnumSet a -> a
maximum = forall w a. (FiniteBits w, Num w, Enum a) => EnumSet w a -> a
E.maximum
{-# INLINE maximum #-}
deleteMin :: ∀ a. AsEnumSet a => EnumSet a -> EnumSet a
deleteMin :: forall a. AsEnumSet a => EnumSet a -> EnumSet a
deleteMin = forall {k} w (a :: k).
(FiniteBits w, Num w) =>
EnumSet w a -> EnumSet w a
E.deleteMin
{-# INLINE deleteMin #-}
deleteMax :: ∀ a. AsEnumSet a => EnumSet a -> EnumSet a
deleteMax :: forall a. AsEnumSet a => EnumSet a -> EnumSet a
deleteMax = forall {k} w (a :: k).
(FiniteBits w, Num w) =>
EnumSet w a -> EnumSet w a
E.deleteMax
{-# INLINE deleteMax #-}
minView :: ∀ a. AsEnumSet a => EnumSet a -> Maybe (a, EnumSet a)
minView :: forall a. AsEnumSet a => EnumSet a -> Maybe (a, EnumSet a)
minView = forall w a.
(FiniteBits w, Num w, Enum a) =>
EnumSet w a -> Maybe (a, EnumSet w a)
E.minView
{-# INLINE minView #-}
maxView :: ∀ a. AsEnumSet a => EnumSet a -> Maybe (a, EnumSet a)
maxView :: forall a. AsEnumSet a => EnumSet a -> Maybe (a, EnumSet a)
maxView = forall w a.
(FiniteBits w, Num w, Enum a) =>
EnumSet w a -> Maybe (a, EnumSet w a)
E.maxView
{-# INLINE maxView #-}
toList :: ∀ a. AsEnumSet a => EnumSet a -> [a]
toList :: forall a. AsEnumSet a => EnumSet a -> [a]
toList = forall w a. (FiniteBits w, Num w, Enum a) => EnumSet w a -> [a]
E.toList
{-# INLINE toList #-}
fromRaw :: ∀ a. AsEnumSet a => EnumSetRep a -> EnumSet a
fromRaw :: forall a. AsEnumSet a => EnumSetRep a -> EnumSet a
fromRaw = forall {k} w (a :: k). w -> EnumSet w a
E.fromRaw
{-# INLINE fromRaw #-}
toRaw :: ∀ a. AsEnumSet a => EnumSet a -> EnumSetRep a
toRaw :: forall a. AsEnumSet a => EnumSet a -> EnumSetRep a
toRaw = forall {k} w (a :: k). EnumSet w a -> w
E.toRaw
{-# INLINE toRaw #-}