{-# LANGUAGE CPP #-}
module Data.IntSet.Refined
(
KnownIntSet
, IntSet
, InSet(..)
, Flavor(Int)
, Element
, revealPredicate
, SomeIntSet(..)
, withIntSet
, SomeIntSetWith(..)
, withIntSetWith
, Some2IntSetWith(..)
, with2IntSetWith
, (:->)
, SupersetProof(..)
, EmptyProof(..)
, empty
, singleton
, SingletonProof(..)
, fromIntSet
, fromTraversable
, FromTraversableProof(..)
, insert
, InsertProof(..)
, delete
, member
, lookupLT
, lookupGT
, lookupLE
, lookupGE
, null
, isSubsetOf
, SubsetProof(..)
, disjoint
, DisjointProof(..)
, union
, UnionProof(..)
, difference
, DifferenceProof(..)
, intersection
, IntersectionProof(..)
, filter
, partition
, PartitionProof(..)
, spanAntitone
, PartialPartitionProof(..)
, splitMember
, SplitProof(..)
, map
, MapProof(..)
, foldMap
, foldr
, foldl
, foldr'
, foldl'
, minView
, maxView
, toList
, toDescList
, asSet
, asHashSet
, castElement
, cast
, castFlavor
) where
import Data.Coerce
import Data.Constraint (Dict(..))
import Data.Container.Refined.Conversion
import Data.Container.Refined.Proofs
import Data.Container.Refined.Unsafe
import qualified Data.Foldable as Foldable
import qualified Data.IntMap as IntMap
import qualified Data.IntSet as IntSet
import Data.Proxy
import Data.Reflection
import Data.Traversable
import Data.Type.Coercion
import Data.Type.Equality ((:~:)(..))
import GHC.Exts (Proxy#, proxy#)
import Prelude hiding (filter, foldl, foldMap, foldr, map, null)
import Refined
import Refined.Unsafe
import Unsafe.Coerce
#if MIN_VERSION_containers(0, 6, 7)
#else
import qualified Data.List as List
#endif
revealPredicate
:: forall s. KnownIntSet s => Dict (Predicate (InSet 'Int s) Int)
revealPredicate :: forall s. KnownIntSet s => Dict (Predicate (InSet 'Int s) Int)
revealPredicate = forall a r.
Typeable a =>
a -> (forall s. (Typeable s, Reifies s a) => Proxy s -> r) -> r
reifyTypeable (forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect (forall {k} (t :: k). Proxy t
Proxy @s))
\(Proxy s
_ :: Proxy s') ->
forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect (forall {k} (t :: k). Proxy t
Proxy @s') seq :: forall a b. a -> b -> b
`seq`
case forall a b. a -> b
unsafeCoerce forall {k} (a :: k). a :~: a
Refl :: s :~: s' of
s :~: s
Refl -> forall (a :: Constraint). a => Dict a
Dict
type Element s = Refined (InSet 'Int s) Int
unsafeCastElement :: forall s. Coercion Int (Element s)
unsafeCastElement :: forall s. Coercion Int (Element s)
unsafeCastElement = forall {k} x (p :: k). Coercion x (Refined p x)
reallyUnsafeUnderlyingRefined
unsafeElement :: Int -> Element s
unsafeElement :: forall s. Int -> Element s
unsafeElement = forall a b. Coercion a b -> a -> b
coerceWith forall s. Coercion Int (Element s)
unsafeCastElement
data SomeIntSet where
SomeIntSet :: forall s. KnownIntSet s => Proxy# s -> SomeIntSet
withIntSet
:: forall r. SomeIntSet -> (forall s. KnownIntSet s => Proxy s -> r) -> r
withIntSet :: forall r.
SomeIntSet -> (forall s. KnownIntSet s => Proxy s -> r) -> r
withIntSet (SomeIntSet (Proxy# s
_ :: Proxy# s)) forall s. KnownIntSet s => Proxy s -> r
k = forall s. KnownIntSet s => Proxy s -> r
k forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s
fromIntSet :: IntSet.IntSet -> SomeIntSet
fromIntSet :: IntSet -> SomeIntSet
fromIntSet IntSet
s = forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify IntSet
s \(Proxy s
_ :: Proxy s) -> forall s. KnownIntSet s => Proxy# s -> SomeIntSet
SomeIntSet @s forall {k} (a :: k). Proxy# a
proxy#
data SomeIntSetWith p where
SomeIntSetWith :: forall s p. KnownIntSet s => !(p s) -> SomeIntSetWith p
withIntSetWith
:: forall r p. SomeIntSetWith p -> (forall s. KnownIntSet s => p s -> r) -> r
withIntSetWith :: forall r (p :: * -> *).
SomeIntSetWith p -> (forall s. KnownIntSet s => p s -> r) -> r
withIntSetWith (SomeIntSetWith p s
p) forall s. KnownIntSet s => p s -> r
k = forall s. KnownIntSet s => p s -> r
k p s
p
data Some2IntSetWith p where
Some2IntSetWith
:: forall s t p. (KnownIntSet s, KnownIntSet t)
=> !(p s t) -> Some2IntSetWith p
with2IntSetWith
:: forall r p. Some2IntSetWith p
-> (forall s t. (KnownIntSet s, KnownIntSet t) => p s t -> r)
-> r
with2IntSetWith :: forall r (p :: * -> * -> *).
Some2IntSetWith p
-> (forall s t. (KnownIntSet s, KnownIntSet t) => p s t -> r) -> r
with2IntSetWith (Some2IntSetWith p s t
p) forall s t. (KnownIntSet s, KnownIntSet t) => p s t -> r
k = forall s t. (KnownIntSet s, KnownIntSet t) => p s t -> r
k p s t
p
empty :: SomeIntSetWith (EmptyProof 'Int)
empty :: SomeIntSetWith (EmptyProof 'Int)
empty = forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify IntSet
IntSet.empty \(Proxy s
_ :: Proxy r)
-> forall s (p :: * -> *). KnownIntSet s => p s -> SomeIntSetWith p
SomeIntSetWith @r forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) r.
(forall s. InSet f r :-> InSet f s) -> EmptyProof f r
EmptyProof forall p q. p :-> q
unsafeSubset
singleton :: Int -> SomeIntSetWith (SingletonProof 'Int Int)
singleton :: Int -> SomeIntSetWith (SingletonProof 'Int Int)
singleton Int
x = forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify (Int -> IntSet
IntSet.singleton Int
x) \(Proxy s
_ :: Proxy r)
-> forall s (p :: * -> *). KnownIntSet s => p s -> SomeIntSetWith p
SomeIntSetWith @r forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) a r.
Refined (InSet f r) a -> SingletonProof f a r
SingletonProof forall a b. (a -> b) -> a -> b
$ forall s. Int -> Element s
unsafeElement Int
x
fromTraversable
:: forall t. Traversable t
=> t Int -> SomeIntSetWith (FromTraversableProof 'Int t Int)
fromTraversable :: forall (t :: * -> *).
Traversable t =>
t Int -> SomeIntSetWith (FromTraversableProof 'Int t Int)
fromTraversable t Int
xs = forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify IntSet
set \(Proxy s
_ :: Proxy r)
-> forall s (p :: * -> *). KnownIntSet s => p s -> SomeIntSetWith p
SomeIntSetWith @r forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) (t :: * -> *) a r.
t (Refined (InSet f r) a) -> FromTraversableProof f t a r
FromTraversableProof
forall a b. (a -> b) -> a -> b
$ forall a b. a -> b
unsafeCoerce @(t (Element _)) @(t (Element r)) t (Element Any)
proof
where
(IntSet
set, t (Element Any)
proof) = forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL
(\IntSet
s Int
x -> let !s' :: IntSet
s' = Int -> IntSet -> IntSet
IntSet.insert Int
x IntSet
s in (IntSet
s', forall s. Int -> Element s
unsafeElement Int
x))
IntSet
IntSet.empty
t Int
xs
insert :: forall s. KnownIntSet s
=> Int -> SomeIntSetWith (InsertProof 'Int Int s)
insert :: forall s.
KnownIntSet s =>
Int -> SomeIntSetWith (InsertProof 'Int Int s)
insert Int
x = forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify (Int -> IntSet -> IntSet
IntSet.insert Int
x forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s) \(Proxy s
_ :: Proxy r)
-> forall s (p :: * -> *). KnownIntSet s => p s -> SomeIntSetWith p
SomeIntSetWith @r forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) a s r.
Refined (InSet f r) a
-> (InSet f s :-> InSet f r) -> InsertProof f a s r
InsertProof (forall s. Int -> Element s
unsafeElement Int
x) forall p q. p :-> q
unsafeSubset
delete :: forall s. KnownIntSet s
=> Int -> SomeIntSetWith (SupersetProof 'Int s)
delete :: forall s.
KnownIntSet s =>
Int -> SomeIntSetWith (SupersetProof 'Int s)
delete Int
x = forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify (Int -> IntSet -> IntSet
IntSet.delete Int
x forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s) \(Proxy s
_ :: Proxy r)
-> forall s (p :: * -> *). KnownIntSet s => p s -> SomeIntSetWith p
SomeIntSetWith @s forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s r.
(InSet f r :-> InSet f s) -> SupersetProof f s r
SupersetProof forall p q. p :-> q
unsafeSubset
member :: forall s. KnownIntSet s => Int -> Maybe (Element s)
member :: forall s. KnownIntSet s => Int -> Maybe (Element s)
member Int
x
| Int
x Int -> IntSet -> Bool
`IntSet.member` forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect (forall {k} (t :: k). Proxy t
Proxy @s) = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall s. Int -> Element s
unsafeElement Int
x
| Bool
otherwise = forall a. Maybe a
Nothing
lookupLT :: forall s. KnownIntSet s => Int -> Maybe (Element s)
lookupLT :: forall s. KnownIntSet s => Int -> Maybe (Element s)
lookupLT Int
x = forall {k} (a :: k) (b :: k) r.
Coercion a b -> (Coercible a b => r) -> r
gcoerceWith (forall s. Coercion Int (Element s)
unsafeCastElement @s) forall a b. (a -> b) -> a -> b
$ coerce :: forall a b. Coercible a b => a -> b
coerce
forall a b. (a -> b) -> a -> b
$ Int -> IntSet -> Maybe Int
IntSet.lookupLT Int
x (forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s)
lookupGT :: forall s. KnownIntSet s => Int -> Maybe (Element s)
lookupGT :: forall s. KnownIntSet s => Int -> Maybe (Element s)
lookupGT Int
x = forall {k} (a :: k) (b :: k) r.
Coercion a b -> (Coercible a b => r) -> r
gcoerceWith (forall s. Coercion Int (Element s)
unsafeCastElement @s) forall a b. (a -> b) -> a -> b
$ coerce :: forall a b. Coercible a b => a -> b
coerce
forall a b. (a -> b) -> a -> b
$ Int -> IntSet -> Maybe Int
IntSet.lookupGT Int
x (forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s)
lookupLE :: forall s. KnownIntSet s => Int -> Maybe (Element s)
lookupLE :: forall s. KnownIntSet s => Int -> Maybe (Element s)
lookupLE Int
x = forall {k} (a :: k) (b :: k) r.
Coercion a b -> (Coercible a b => r) -> r
gcoerceWith (forall s. Coercion Int (Element s)
unsafeCastElement @s) forall a b. (a -> b) -> a -> b
$ coerce :: forall a b. Coercible a b => a -> b
coerce
forall a b. (a -> b) -> a -> b
$ Int -> IntSet -> Maybe Int
IntSet.lookupLE Int
x (forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s)
lookupGE :: forall s. KnownIntSet s => Int -> Maybe (Element s)
lookupGE :: forall s. KnownIntSet s => Int -> Maybe (Element s)
lookupGE Int
x = forall {k} (a :: k) (b :: k) r.
Coercion a b -> (Coercible a b => r) -> r
gcoerceWith (forall s. Coercion Int (Element s)
unsafeCastElement @s) forall a b. (a -> b) -> a -> b
$ coerce :: forall a b. Coercible a b => a -> b
coerce
forall a b. (a -> b) -> a -> b
$ Int -> IntSet -> Maybe Int
IntSet.lookupGE Int
x (forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s)
null :: forall s. KnownIntSet s => Maybe (EmptyProof 'Int s)
null :: forall s. KnownIntSet s => Maybe (EmptyProof 'Int s)
null
| IntSet -> Bool
IntSet.null forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) r.
(forall s. InSet f r :-> InSet f s) -> EmptyProof f r
EmptyProof forall p q. p :-> q
unsafeSubset
| Bool
otherwise = forall a. Maybe a
Nothing
isSubsetOf
:: forall s t. (KnownIntSet s, KnownIntSet t) => Maybe (SubsetProof 'Int s t)
isSubsetOf :: forall s t.
(KnownIntSet s, KnownIntSet t) =>
Maybe (SubsetProof 'Int s t)
isSubsetOf
| forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect (forall {k} (t :: k). Proxy t
Proxy @s) IntSet -> IntSet -> Bool
`IntSet.isSubsetOf` forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect (forall {k} (t :: k). Proxy t
Proxy @t)
= forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s r.
(InSet f s :-> InSet f r) -> SubsetProof f s r
SubsetProof forall p q. p :-> q
unsafeSubset
| Bool
otherwise = forall a. Maybe a
Nothing
disjoint
:: forall s t. (KnownIntSet s, KnownIntSet t)
=> Maybe (DisjointProof 'Int s t)
disjoint :: forall s t.
(KnownIntSet s, KnownIntSet t) =>
Maybe (DisjointProof 'Int s t)
disjoint
#if MIN_VERSION_containers(0, 5, 11)
| IntSet -> IntSet -> Bool
IntSet.disjoint (forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s) (forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @t)
#else
| IntSet.null $ IntSet.intersection (reflect $ Proxy @s) (reflect $ Proxy @t)
#endif
= forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s r.
(forall t.
(InSet f t :-> InSet f s)
-> (InSet f t :-> InSet f r) -> forall u. InSet f t :-> InSet f u)
-> DisjointProof f s r
DisjointProof \InSet 'Int t :-> InSet 'Int s
f InSet 'Int t :-> InSet 'Int t
g -> forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2 InSet 'Int t :-> InSet 'Int s
f InSet 'Int t :-> InSet 'Int t
g
| Bool
otherwise = forall a. Maybe a
Nothing
union
:: forall s t. (KnownIntSet s, KnownIntSet t)
=> SomeIntSetWith (UnionProof 'Int s t)
union :: forall s t.
(KnownIntSet s, KnownIntSet t) =>
SomeIntSetWith (UnionProof 'Int s t)
union = forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify (forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect (forall {k} (t :: k). Proxy t
Proxy @s) IntSet -> IntSet -> IntSet
`IntSet.union` forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect (forall {k} (t :: k). Proxy t
Proxy @t))
\(Proxy s
_ :: Proxy r) -> forall s (p :: * -> *). KnownIntSet s => p s -> SomeIntSetWith p
SomeIntSetWith @r
forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s t r.
((InSet f s || InSet f t) :-> InSet f r)
-> (forall u.
(InSet f s :-> InSet f u)
-> (InSet f t :-> InSet f u) -> InSet f r :-> InSet f u)
-> UnionProof f s t r
UnionProof forall p q. p :-> q
unsafeSubset forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2
difference
:: forall s t. (KnownIntSet s, KnownIntSet t)
=> SomeIntSetWith (DifferenceProof 'Int s t)
difference :: forall s t.
(KnownIntSet s, KnownIntSet t) =>
SomeIntSetWith (DifferenceProof 'Int s t)
difference = forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify (forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect (forall {k} (t :: k). Proxy t
Proxy @s) IntSet -> IntSet -> IntSet
`IntSet.difference` forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect (forall {k} (t :: k). Proxy t
Proxy @t))
\(Proxy s
_ :: Proxy r) -> forall s (p :: * -> *). KnownIntSet s => p s -> SomeIntSetWith p
SomeIntSetWith @r
forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s t r.
(InSet f r :-> InSet f s)
-> (forall u.
(InSet f u :-> InSet f r)
-> (InSet f u :-> InSet f t) -> forall v. InSet f u :-> InSet f v)
-> (InSet f s :-> (InSet f t || InSet f r))
-> DifferenceProof f s t r
DifferenceProof forall p q. p :-> q
unsafeSubset (\InSet 'Int u :-> InSet 'Int s
f InSet 'Int u :-> InSet 'Int t
g -> forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2 InSet 'Int u :-> InSet 'Int s
f InSet 'Int u :-> InSet 'Int t
g) forall p q. p :-> q
unsafeSubset
intersection
:: forall s t. (KnownIntSet s, KnownIntSet t)
=> SomeIntSetWith (IntersectionProof 'Int s t)
intersection :: forall s t.
(KnownIntSet s, KnownIntSet t) =>
SomeIntSetWith (IntersectionProof 'Int s t)
intersection
= forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify (forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect (forall {k} (t :: k). Proxy t
Proxy @s) IntSet -> IntSet -> IntSet
`IntSet.intersection` forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect (forall {k} (t :: k). Proxy t
Proxy @t))
\(Proxy s
_ :: Proxy r) -> forall s (p :: * -> *). KnownIntSet s => p s -> SomeIntSetWith p
SomeIntSetWith @r
forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s t r.
(InSet f r :-> (InSet f s && InSet f t))
-> (forall u.
(InSet f u :-> InSet f s)
-> (InSet f u :-> InSet f t) -> InSet f u :-> InSet f r)
-> IntersectionProof f s t r
IntersectionProof forall p q. p :-> q
unsafeSubset forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2
filter
:: forall s. KnownIntSet s
=> (Element s -> Bool) -> SomeIntSetWith (SupersetProof 'Int s)
filter :: forall s.
KnownIntSet s =>
(Element s -> Bool) -> SomeIntSetWith (SupersetProof 'Int s)
filter Element s -> Bool
p = forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify ((Int -> Bool) -> IntSet -> IntSet
IntSet.filter (Element s -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Int -> Element s
unsafeElement) forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s)
\(Proxy s
_ :: Proxy r) -> forall s (p :: * -> *). KnownIntSet s => p s -> SomeIntSetWith p
SomeIntSetWith @r forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s r.
(InSet f r :-> InSet f s) -> SupersetProof f s r
SupersetProof forall p q. p :-> q
unsafeSubset
partition
:: forall s. KnownIntSet s
=> (Element s -> Bool) -> Some2IntSetWith (PartitionProof 'Int s Int)
partition :: forall s.
KnownIntSet s =>
(Element s -> Bool) -> Some2IntSetWith (PartitionProof 'Int s Int)
partition Element s -> Bool
p = case (Int -> Bool) -> IntSet -> (IntSet, IntSet)
IntSet.partition (Element s -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Int -> Element s
unsafeElement) forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s of
(IntSet
r, IntSet
q) -> forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify IntSet
r \(Proxy s
_ :: Proxy r) -> forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify IntSet
q \(Proxy s
_ :: Proxy q)
-> forall s t (p :: * -> * -> *).
(KnownIntSet s, KnownIntSet t) =>
p s t -> Some2IntSetWith p
Some2IntSetWith @s @r forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s a r q.
(Refined (InSet f s) a
-> Either (Refined (InSet f r) a) (Refined (InSet f q) a))
-> ((InSet f r || InSet f q) :-> InSet f s)
-> (forall t.
(InSet f r :-> InSet f t)
-> (InSet f q :-> InSet f t) -> InSet f s :-> InSet f t)
-> (forall t.
(InSet f t :-> InSet f r)
-> (InSet f t :-> InSet f q) -> forall u. InSet f t :-> InSet f u)
-> PartitionProof f s a r q
PartitionProof
do \Element s
x -> if Element s -> Bool
p Element s
x
then forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall s. Int -> Element s
unsafeElement forall a b. (a -> b) -> a -> b
$ forall {k} (p :: k) x. Refined p x -> x
unrefine Element s
x
else forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ forall s. Int -> Element s
unsafeElement forall a b. (a -> b) -> a -> b
$ forall {k} (p :: k) x. Refined p x -> x
unrefine Element s
x
forall p q. p :-> q
unsafeSubset forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2 \InSet 'Int t :-> InSet 'Int s
f InSet 'Int t :-> InSet 'Int s
g -> forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2 InSet 'Int t :-> InSet 'Int s
f InSet 'Int t :-> InSet 'Int s
g
spanAntitone
:: forall s. KnownIntSet s
=> (Element s -> Bool) -> Some2IntSetWith (PartialPartitionProof 'Int s)
spanAntitone :: forall s.
KnownIntSet s =>
(Element s -> Bool)
-> Some2IntSetWith (PartialPartitionProof 'Int s)
spanAntitone Element s -> Bool
p =
#if MIN_VERSION_containers(0, 6, 7)
case IntSet.spanAntitone (p . unsafeElement) $ reflect $ Proxy @s of
(r, q)
#else
case forall a. (a -> Bool) -> [a] -> ([a], [a])
List.span (Element s -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Int -> Element s
unsafeElement)
forall a b. (a -> b) -> a -> b
$ IntSet -> [Int]
IntSet.toAscList forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s of
([Int]
rs, [Int]
qs)
| let r :: IntSet
r = [Int] -> IntSet
IntSet.fromDistinctAscList [Int]
rs
, let q :: IntSet
q = [Int] -> IntSet
IntSet.fromDistinctAscList [Int]
qs
#endif
-> forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify IntSet
r \(Proxy s
_ :: Proxy r) -> forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify IntSet
q \(Proxy s
_ :: Proxy q)
-> forall s t (p :: * -> * -> *).
(KnownIntSet s, KnownIntSet t) =>
p s t -> Some2IntSetWith p
Some2IntSetWith @r @q forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s r q.
((InSet f r || InSet f q) :-> InSet f s)
-> (forall t.
(InSet f r :-> InSet f t)
-> (InSet f q :-> InSet f t) -> InSet f s :-> InSet f t)
-> (forall t.
(InSet f t :-> InSet f r)
-> (InSet f t :-> InSet f q) -> forall u. InSet f t :-> InSet f u)
-> PartialPartitionProof f s r q
PartialPartitionProof
forall p q. p :-> q
unsafeSubset forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2 \InSet 'Int t :-> InSet 'Int s
f InSet 'Int t :-> InSet 'Int s
g -> forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2 InSet 'Int t :-> InSet 'Int s
f InSet 'Int t :-> InSet 'Int s
g
splitMember
:: forall s. KnownIntSet s
=> Int -> Some2IntSetWith (SplitProof 'Int s (Element s))
splitMember :: forall s.
KnownIntSet s =>
Int -> Some2IntSetWith (SplitProof 'Int s (Element s))
splitMember Int
x = case Int -> IntSet -> (IntSet, Bool, IntSet)
IntSet.splitMember Int
x forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s of
(IntSet
r, Bool
m, IntSet
q) -> forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify IntSet
r \(Proxy s
_ :: Proxy r) -> forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify IntSet
q \(Proxy s
_ :: Proxy q)
-> forall s t (p :: * -> * -> *).
(KnownIntSet s, KnownIntSet t) =>
p s t -> Some2IntSetWith p
Some2IntSetWith @r @q forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s e r q.
Maybe e
-> ((InSet f r || InSet f q) :-> InSet f s)
-> (forall t.
(InSet f t :-> InSet f r)
-> (InSet f t :-> InSet f q) -> forall u. InSet f t :-> InSet f u)
-> SplitProof f s e r q
SplitProof
(if Bool
m then forall a. a -> Maybe a
Just (forall s. Int -> Element s
unsafeElement Int
x) else forall a. Maybe a
Nothing)
forall p q. p :-> q
unsafeSubset \InSet 'Int t :-> InSet 'Int s
f InSet 'Int t :-> InSet 'Int s
g -> forall p' q' p'' q'' p q. (p' :-> q') -> (p'' :-> q'') -> p :-> q
unsafeSubsetWith2 InSet 'Int t :-> InSet 'Int s
f InSet 'Int t :-> InSet 'Int s
g
map
:: forall s. KnownIntSet s
=> (Element s -> Int) -> SomeIntSetWith (MapProof 'Int s Int Int)
map :: forall s.
KnownIntSet s =>
(Element s -> Int) -> SomeIntSetWith (MapProof 'Int s Int Int)
map Element s -> Int
f = forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify (forall a. IntMap a -> IntSet
IntMap.keysSet IntMap (Element s)
m) \(Proxy s
_ :: Proxy r) -> forall s (p :: * -> *). KnownIntSet s => p s -> SomeIntSetWith p
SomeIntSetWith @r
forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s a b r.
(Refined (InSet f s) a -> Refined (InSet f r) b)
-> (Refined (InSet f r) b -> Refined (InSet f s) a)
-> MapProof f s a b r
MapProof (forall s. Int -> Element s
unsafeElement forall b c a. (b -> c) -> (a -> b) -> a -> c
. Element s -> Int
f) \Refined (InSet 'Int s) Int
y -> case forall a. Int -> IntMap a -> Maybe a
IntMap.lookup (forall {k} (p :: k) x. Refined p x -> x
unrefine Refined (InSet 'Int s) Int
y) IntMap (Element s)
m of
Maybe (Element s)
Nothing -> forall a. HasCallStack => [Char] -> a
error [Char]
"map: bug: Data.IntSet.Refined has been subverted"
Just Element s
x -> Element s
x
where
!m :: IntMap (Element s)
m = forall a. [(Int, a)] -> IntMap a
IntMap.fromList
[ (Int
y, forall s. Int -> Element s
unsafeElement Int
x)
| Int
x <- IntSet -> [Int]
IntSet.toList forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s
, let !y :: Int
y = Element s -> Int
f forall a b. (a -> b) -> a -> b
$ forall s. Int -> Element s
unsafeElement Int
x
]
foldMap :: forall s m. (KnownIntSet s, Monoid m) => (Element s -> m) -> m
foldMap :: forall s m. (KnownIntSet s, Monoid m) => (Element s -> m) -> m
foldMap Element s -> m
f = IntSet -> m
go forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s
where
go :: IntSet -> m
go IntSet
s = case IntSet -> [IntSet]
IntSet.splitRoot IntSet
s of
[IntSet
s'] -> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Foldable.foldMap (Element s -> m
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Int -> Element s
unsafeElement) forall a b. (a -> b) -> a -> b
$ IntSet -> [Int]
IntSet.toAscList IntSet
s'
[IntSet]
xs -> forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Foldable.foldMap IntSet -> m
go [IntSet]
xs
foldr :: forall s a. KnownIntSet s => (Element s -> a -> a) -> a -> a
foldr :: forall s a. KnownIntSet s => (Element s -> a -> a) -> a -> a
foldr Element s -> a -> a
f a
z = forall b. (Int -> b -> b) -> b -> IntSet -> b
IntSet.foldr (Element s -> a -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Int -> Element s
unsafeElement) a
z forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s
foldl :: forall s a. KnownIntSet s => (a -> Element s -> a) -> a -> a
foldl :: forall s a. KnownIntSet s => (a -> Element s -> a) -> a -> a
foldl a -> Element s -> a
f a
z = forall a. (a -> Int -> a) -> a -> IntSet -> a
IntSet.foldl ((forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Int -> Element s
unsafeElement) forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Element s -> a
f) a
z forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s
foldr' :: forall s a. KnownIntSet s => (Element s -> a -> a) -> a -> a
foldr' :: forall s a. KnownIntSet s => (Element s -> a -> a) -> a -> a
foldr' Element s -> a -> a
f a
z = forall b. (Int -> b -> b) -> b -> IntSet -> b
IntSet.foldr' (Element s -> a -> a
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Int -> Element s
unsafeElement) a
z forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s
foldl' :: forall s a. KnownIntSet s => (a -> Element s -> a) -> a -> a
foldl' :: forall s a. KnownIntSet s => (a -> Element s -> a) -> a -> a
foldl' a -> Element s -> a
f a
z = forall a. (a -> Int -> a) -> a -> IntSet -> a
IntSet.foldl' ((forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s. Int -> Element s
unsafeElement) forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Element s -> a
f) a
z forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s
minView
:: forall s. KnownIntSet s
=> Either
(EmptyProof 'Int s)
(Element s, SomeIntSetWith (SupersetProof 'Int s))
minView :: forall s.
KnownIntSet s =>
Either
(EmptyProof 'Int s)
(Element s, SomeIntSetWith (SupersetProof 'Int s))
minView = case IntSet -> Maybe (Int, IntSet)
IntSet.minView forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s of
Maybe (Int, IntSet)
Nothing -> forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) r.
(forall s. InSet f r :-> InSet f s) -> EmptyProof f r
EmptyProof forall p q. p :-> q
unsafeSubset
Just (Int
x, IntSet
xs) -> forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ (forall s. Int -> Element s
unsafeElement Int
x,) forall a b. (a -> b) -> a -> b
$ forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify IntSet
xs \(Proxy s
_ :: Proxy r)
-> forall s (p :: * -> *). KnownIntSet s => p s -> SomeIntSetWith p
SomeIntSetWith @r forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s r.
(InSet f r :-> InSet f s) -> SupersetProof f s r
SupersetProof forall p q. p :-> q
unsafeSubset
maxView
:: forall s. KnownIntSet s
=> Either
(EmptyProof 'Int s)
(Element s, SomeIntSetWith (SupersetProof 'Int s))
maxView :: forall s.
KnownIntSet s =>
Either
(EmptyProof 'Int s)
(Element s, SomeIntSetWith (SupersetProof 'Int s))
maxView = case IntSet -> Maybe (Int, IntSet)
IntSet.maxView forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s of
Maybe (Int, IntSet)
Nothing -> forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) r.
(forall s. InSet f r :-> InSet f s) -> EmptyProof f r
EmptyProof forall p q. p :-> q
unsafeSubset
Just (Int
x, IntSet
xs) -> forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ (forall s. Int -> Element s
unsafeElement Int
x,) forall a b. (a -> b) -> a -> b
$ forall a r. a -> (forall s. Reifies s a => Proxy s -> r) -> r
reify IntSet
xs \(Proxy s
_ :: Proxy r)
-> forall s (p :: * -> *). KnownIntSet s => p s -> SomeIntSetWith p
SomeIntSetWith @r forall a b. (a -> b) -> a -> b
$ forall (f :: Flavor) s r.
(InSet f r :-> InSet f s) -> SupersetProof f s r
SupersetProof forall p q. p :-> q
unsafeSubset
toList :: forall s. KnownIntSet s => [Element s]
toList :: forall s. KnownIntSet s => [Element s]
toList = forall {k} (a :: k) (b :: k) r.
Coercion a b -> (Coercible a b => r) -> r
gcoerceWith (forall s. Coercion Int (Element s)
unsafeCastElement @s) forall a b. (a -> b) -> a -> b
$ coerce :: forall a b. Coercible a b => a -> b
coerce
forall a b. (a -> b) -> a -> b
$ IntSet -> [Int]
IntSet.toAscList forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s
toDescList :: forall s. KnownIntSet s => [Element s]
toDescList :: forall s. KnownIntSet s => [Element s]
toDescList = forall {k} (a :: k) (b :: k) r.
Coercion a b -> (Coercible a b => r) -> r
gcoerceWith (forall s. Coercion Int (Element s)
unsafeCastElement @s) forall a b. (a -> b) -> a -> b
$ coerce :: forall a b. Coercible a b => a -> b
coerce
forall a b. (a -> b) -> a -> b
$ IntSet -> [Int]
IntSet.toDescList forall a b. (a -> b) -> a -> b
$ forall {k} (s :: k) a (proxy :: k -> *).
Reifies s a =>
proxy s -> a
reflect forall a b. (a -> b) -> a -> b
$ forall {k} (t :: k). Proxy t
Proxy @s
asSet :: forall s. KnownIntSet s => Set s Int
asSet :: forall s. KnownIntSet s => Set s Int
asSet = forall s. KnownIntSet s => Set s Int
intSet2Set
asHashSet :: forall s. KnownIntSet s => HashSet s Int
asHashSet :: forall s. KnownIntSet s => HashSet s Int
asHashSet = forall s. KnownIntSet s => HashSet s Int
intSet2HashSet
castElement
:: forall s t a.
(forall x. Refined (InSet 'Int s) x -> Refined (InSet 'Int t) x)
-> (forall x. Refined (InSet 'Int t) x -> Refined (InSet 'Int s) x)
-> Coercion (Refined (InSet 'Int s) a) (Refined (InSet 'Int t) a)
castElement :: forall s t a.
(forall x. Refined (InSet 'Int s) x -> Refined (InSet 'Int t) x)
-> (forall x. Refined (InSet 'Int t) x -> Refined (InSet 'Int s) x)
-> Coercion (Refined (InSet 'Int s) a) (Refined (InSet 'Int t) a)
castElement = forall a p q.
(p :-> q) -> (q :-> p) -> Coercion (Refined p a) (Refined q a)
castRefined
cast
:: forall s t. (forall x. Coercion
(Refined (InSet 'Int s) x)
(Refined (InSet 'Int t) x))
-> Coercion (IntSet s) (IntSet t)
cast :: forall s t.
(forall x.
Coercion (Refined (InSet 'Int s) x) (Refined (InSet 'Int t) x))
-> Coercion (IntSet s) (IntSet t)
cast Coercion (Refined (InSet 'Int s) Any) (Refined (InSet 'Int t) Any)
forall x.
Coercion (Refined (InSet 'Int s) x) (Refined (InSet 'Int t) x)
Coercion
#if MIN_VERSION_base(4, 15, 0)
= case forall {k} (a :: k) (b :: k). UnsafeEquality a b
unsafeEqualityProof @s @t of UnsafeEquality s t
UnsafeRefl -> forall {k} (a :: k) (b :: k). Coercible a b => Coercion a b
Coercion
#else
= repr $ unsafeCoerce Refl
#endif