Copyright | (C) Koz Ross 2019 |
---|---|
License | GPL version 3.0 or later |
Maintainer | koz.ross@retro-freedom.nz |
Stability | Experimental |
Portability | GHC only |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
Defines a newtype for easy derivation of Unbox
, Storable
,
Binary
and Hashable
instances for any type with a Finitary
instance. The easiest way to use
this is with the DerivingVia
extension:
{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DerivingVia #-} import Data.Finitary import Data.Finitary.Pack import Data.Word import Data.Hashable data Foo = Bar | Baz (Word8, Word8) | Quux Word16 deriving (Eq, Generic, Finitary) deriving (Storable, Binary, Hashable) via (Pack Foo)
Alternatively, you can just use Pack a
instead of a
wherever appropriate.
Unfortunately (due to role restrictions on unboxed vectors), you must use
Pack a
if you want a Vector
full of a
s -
DerivingVia
is of no help here.
Documentation
Essentially Identity a
, but with different instances. So named due to the 'packing' of the
type's indices densely into arrays, memory or bits.
Instances
Functor Pack Source # | |
(Finitary a, 1 <= Cardinality a) => Vector Vector (Pack a) Source # | |
Defined in Data.Finitary.Pack basicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (Pack a) -> m (Vector (Pack a)) basicUnsafeThaw :: PrimMonad m => Vector (Pack a) -> m (Mutable Vector (PrimState m) (Pack a)) basicLength :: Vector (Pack a) -> Int basicUnsafeSlice :: Int -> Int -> Vector (Pack a) -> Vector (Pack a) basicUnsafeIndexM :: Monad m => Vector (Pack a) -> Int -> m (Pack a) basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (Pack a) -> Vector (Pack a) -> m () | |
(Finitary a, 1 <= Cardinality a) => MVector MVector (Pack a) Source # | |
Defined in Data.Finitary.Pack basicLength :: MVector s (Pack a) -> Int basicUnsafeSlice :: Int -> Int -> MVector s (Pack a) -> MVector s (Pack a) basicOverlaps :: MVector s (Pack a) -> MVector s (Pack a) -> Bool basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) (Pack a)) basicInitialize :: PrimMonad m => MVector (PrimState m) (Pack a) -> m () basicUnsafeReplicate :: PrimMonad m => Int -> Pack a -> m (MVector (PrimState m) (Pack a)) basicUnsafeRead :: PrimMonad m => MVector (PrimState m) (Pack a) -> Int -> m (Pack a) basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) (Pack a) -> Int -> Pack a -> m () basicClear :: PrimMonad m => MVector (PrimState m) (Pack a) -> m () basicSet :: PrimMonad m => MVector (PrimState m) (Pack a) -> Pack a -> m () basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) (Pack a) -> MVector (PrimState m) (Pack a) -> m () basicUnsafeMove :: PrimMonad m => MVector (PrimState m) (Pack a) -> MVector (PrimState m) (Pack a) -> m () basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) (Pack a) -> Int -> m (MVector (PrimState m) (Pack a)) | |
Bounded a => Bounded (Pack a) Source # | |
Eq a => Eq (Pack a) Source # | |
Data a => Data (Pack a) Source # | |
Defined in Data.Finitary.Pack gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Pack a -> c (Pack a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Pack a) # toConstr :: Pack a -> Constr # dataTypeOf :: Pack a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Pack a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Pack a)) # gmapT :: (forall b. Data b => b -> b) -> Pack a -> Pack a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Pack a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Pack a -> r # gmapQ :: (forall d. Data d => d -> u) -> Pack a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Pack a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Pack a -> m (Pack a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Pack a -> m (Pack a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Pack a -> m (Pack a) # | |
Ord a => Ord (Pack a) Source # | |
Read a => Read (Pack a) Source # | |
Show a => Show (Pack a) Source # | |
Generic (Pack a) Source # | |
Semigroup a => Semigroup (Pack a) Source # | |
Monoid a => Monoid (Pack a) Source # | |
(Finitary a, 1 <= Cardinality a) => Storable (Pack a) Source # | As |
(Finitary a, 1 <= Cardinality a) => Binary (Pack a) Source # | We can serialize any |
NFData a => NFData (Pack a) Source # | |
Defined in Data.Finitary.Pack | |
Finitary a => Finitary (Pack a) Source # | |
Defined in Data.Finitary.Pack fromFinite :: Finite (Cardinality (Pack a)) -> Pack a toFinite :: Pack a -> Finite (Cardinality (Pack a)) previous :: Alternative f => Pack a -> f (Pack a) previousSkipping :: Alternative f => Finite (Cardinality (Pack a)) -> Pack a -> f (Pack a) next :: Alternative f => Pack a -> f (Pack a) nextSkipping :: Alternative f => Finite (Cardinality (Pack a)) -> Pack a -> f (Pack a) enumerateFrom :: Pack a -> [Pack a] enumerateFromThen :: Pack a -> Pack a -> [Pack a] enumerateFromTo :: Pack a -> Pack a -> [Pack a] enumerateFromThenTo :: Pack a -> Pack a -> Pack a -> [Pack a] | |
(Finitary a, 1 <= Cardinality a) => Unbox (Pack a) Source # | We can rely on the fact that indexes of any |
Defined in Data.Finitary.Pack | |
(Finitary a, 1 <= Cardinality a) => Hashable (Pack a) Source # | We can hash any |
Defined in Data.Finitary.Pack | |
Generic1 Pack Source # | |
newtype MVector s (Pack a) Source # | |
Defined in Data.Finitary.Pack | |
type Rep (Pack a) Source # | |
Defined in Data.Finitary.Pack | |
type Cardinality (Pack a) Source # | |
Defined in Data.Finitary.Pack | |
newtype Vector (Pack a) Source # | |
Defined in Data.Finitary.Pack | |
type Rep1 Pack Source # | |
Defined in Data.Finitary.Pack |