Safe Haskell | None |
---|---|
Language | Haskell2010 |
Set with and without interfaces. We provide instances for sets, and
sets with one or two interfaces. The First
and Last
annotation is
purely cosmetical (apart from introducing type safety).
- newtype Boundary i t = Boundary {
- getBoundary :: Int
- data First
- data Last
- data Any
- newtype BitSet t = BitSet {}
- bitSetI :: Int -> BitSet I
- bitSetO :: Int -> BitSet O
- bitSetC :: Int -> BitSet C
- data BS1 i t = BS1 !(BitSet t) !(Boundary i t)
- data BS2 i j t = BS2 !(BitSet t) !(Boundary i t) !(Boundary j t)
- class SetPredSucc s where
- type family Mask s :: *
- data Fixed t = Fixed {
- getFixedMask :: Mask t
- getFixed :: !t
- class ApplyMask s where
- streamUpBndMk :: Monad m => Boundary k i -> Boundary k i -> t -> m (t, Boundary k i)
- streamUpBndStep :: Monad m => Boundary k i -> Boundary k i -> (t, Boundary k i) -> m (Step (t, Boundary k i) (t :. Boundary k i))
- streamDownBndMk :: Monad m => Boundary k i -> Boundary k i -> t -> m (t, Boundary k i)
- streamDownBndStep :: Monad m => Boundary k i -> Boundary k i -> (t, Boundary k i) -> m (Step (t, Boundary k i) (t :. Boundary k i))
- streamUpBsMk :: (Monad m, Ord a) => a -> a -> t -> m (t, Maybe a)
- streamUpBsStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s))
- streamDownBsMk :: (Monad m, Ord a) => a -> a -> t -> m (t, Maybe a)
- streamDownBsStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s))
- streamUpBsIMk :: Monad m => BS1 a i -> BS1 b i -> z -> m (z, Maybe (BS1 c i))
- streamUpBsIStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s))
- streamDownBsIMk :: Monad m => BS1 a i -> BS1 b i -> z -> m (z, Maybe (BS1 c i))
- streamDownBsIStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s))
- streamUpBsIiMk :: Monad m => BS2 a b i -> BS2 c d i -> z -> m (z, Maybe (BS2 e f i))
- streamUpBsIiStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s))
- streamDownBsIiMk :: Monad m => BS2 a b i -> BS2 c d i -> z -> m (z, Maybe (BS2 e f i))
- streamDownBsIiStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s))
- testBsS :: BitSet t -> Maybe (Fixed (BitSet t))
- arbitraryBitSetMax :: Integer
newtype
s, data
types, class
es.
Certain sets have an interface, a particular element with special
meaning. In this module, certain `meanings'
are already provided.
These include a First
element and a Last
element. We phantom-type
these to reduce programming overhead.
Vector Vector (Boundary i0 t0) Source # | |
MVector MVector (Boundary i0 t0) Source # | |
Eq (Boundary i t) Source # | |
Num (Boundary i t) Source # | |
Ord (Boundary i t) Source # | |
Show (Boundary i t) Source # | |
Generic (Boundary i t) Source # | |
Hashable (Boundary i t) Source # | |
ToJSON (Boundary i t) Source # | |
FromJSON (Boundary i t) Source # | |
Binary (Boundary i t) Source # | |
Serialize (Boundary i t) Source # | |
NFData (Boundary i t) Source # | |
Unbox (Boundary i0 t0) Source # | |
IndexStream z => IndexStream ((:.) z (Boundary k I)) Source # | |
IndexStream ((:.) Z (Boundary k I)) => IndexStream (Boundary k I) Source # | |
Index (Boundary i t) Source # | |
data MVector s (Boundary i0 t0) Source # | |
type Rep (Boundary i t) Source # | |
data Vector (Boundary i0 t0) Source # | |
Declare the interface to match anything.
TODO needed? want to use later in ADPfusion
Newtype for a bitset. We'd use Word
s but that requires more shape
instances.
TODO can we use Word
s now?
A bitset with one interface.
SetPredSucc (Fixed (BS1 i t)) Source # | |
Show (BS1 i t) Source # | |
Arbitrary (BS1 i t) Source # | |
IndexStream z => IndexStream ((:.) z (BS1 i C)) Source # | |
IndexStream z => IndexStream ((:.) z (BS1 i O)) Source # | |
IndexStream z => IndexStream ((:.) z (BS1 i I)) Source # | |
IndexStream ((:.) Z (BS1 i t)) => IndexStream (BS1 i t) Source # | |
Index (BS1 i t) Source # |
|
ApplyMask (BS1 i t) Source # | |
SetPredSucc (BS1 i t) Source # | |
type Mask (BS1 i t) Source # | |
A bitset with two interfaces.
SetPredSucc (Fixed (BS2 i j t)) Source # | |
IndexStream z => IndexStream ((:.) z (BS2 i j C)) Source # | |
IndexStream z => IndexStream ((:.) z (BS2 i j O)) Source # | |
IndexStream z => IndexStream ((:.) z (BS2 i j I)) Source # | |
Show (BS2 i j t) Source # | |
Arbitrary (BS2 i j t) Source # | |
IndexStream ((:.) Z (BS2 i j t)) => IndexStream (BS2 i j t) Source # | |
Index (BS2 i j t) Source # | |
ApplyMask (BS2 i j t) Source # | |
SetPredSucc (BS2 i j t) Source # | |
type Mask (BS2 i j t) Source # | |
class SetPredSucc s where Source #
Successor and Predecessor for sets. Designed as a class to accomodate sets with interfaces and without interfaces with one function.
The functions are not written recursively, as we currently only have three cases, and we do not want to "reset" while generating successors and predecessors.
Note that sets have a partial order. Within the group of element with
the same popCount
, we use popPermutation
which has the same stepping
order for both, setSucc
and setPred
.
setSucc :: s -> s -> s -> Maybe s Source #
Set successor. The first argument is the lower set limit, the second the upper set limit, the third the current set.
setPred :: s -> s -> s -> Maybe s Source #
Set predecessor. The first argument is the lower set limit, the second the upper set limit, the third the current set.
SetPredSucc (Fixed (BS2 i j t)) Source # | |
SetPredSucc (Fixed (BS1 i t)) Source # | |
SetPredSucc (Fixed (BitSet t)) Source # | |
SetPredSucc (BitSet t) Source # | |
SetPredSucc (BS1 i t) Source # | |
SetPredSucc (BS2 i j t) Source # | |
type family Mask s :: * Source #
Masks are used quite often for different types of bitsets. We liberate them as a type family.
Fixed
allows us to fix some or all bits of a bitset, thereby
providing succ/pred
operations which are only partially free.
The mask is lazy, this allows us to have undefined
for l
and h
.
f = getFixedMask .&. getFixed
are the fixed bits.
n = getFixed .&. complement getFixedMask
are the free bits.
to = complement getFixed
is the to move mask
n' = popShiftR to n
yields the population after the move
p = popPermutation undefined n'
yields the new population permutation
p' = popShiftL to p
yields the population moved back
final = p' .|. f
Fixed | |
|
class ApplyMask s where Source #
Assuming a bitset on bits [0 .. highbit]
, we can apply a mask that
stretches out those bits over [0 .. higherBit]
with highbit <=
higherBit
. Any active interfaces are correctly set as well.
Instances
streamUpBndStep :: Monad m => Boundary k i -> Boundary k i -> (t, Boundary k i) -> m (Step (t, Boundary k i) (t :. Boundary k i)) Source #
streamDownBndStep :: Monad m => Boundary k i -> Boundary k i -> (t, Boundary k i) -> m (Step (t, Boundary k i) (t :. Boundary k i)) Source #
streamUpBsStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s)) Source #
streamDownBsStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s)) Source #
BS1
streamUpBsIStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s)) Source #
streamDownBsIStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s)) Source #
BS2
streamUpBsIiStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s)) Source #
streamDownBsIiStep :: (Monad m, SetPredSucc s) => s -> s -> (t, Maybe s) -> m (Step (t, Maybe s) (t :. s)) Source #