extensible-0.4.9: Extensible, efficient, optics-friendly data types and effects

Copyright(c) Fumiaki Kinoshita 2018
LicenseBSD3
MaintainerFumiaki Kinoshita <fumiexcel@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Data.Extensible.Bits

Description

Bit-packed records

Synopsis

Documentation

newtype BitProd r (h :: k -> *) (xs :: [k]) #

Bit-vector product. It has similar interface as (:*) but fields are packed into r.

Constructors

BitProd 

Fields

Instances

(Corepresentable p, Comonad (Corep p), Functor f) => Extensible k f p (BitProd k r) # 

Associated Types

type ExtensibleConstr f (t :: (f -> *) -> [f] -> *) (h :: f -> *) (xs :: [f]) (x :: f) :: Constraint #

Methods

pieceAt :: ExtensibleConstr f t h xs x => Membership f xs x -> Optic' * * (BitProd k r) p (t h xs) (h x) #

(Bits r, KnownNat (TotalBits k h xs)) => FromBits r (BitProd k r h xs) # 

Associated Types

type BitWidth (BitProd k r h xs) :: Nat #

Methods

fromBits :: r -> BitProd k r h xs #

toBits :: BitProd k r h xs -> r #

Bounded r => Bounded (BitProd k r h xs) # 

Methods

minBound :: BitProd k r h xs #

maxBound :: BitProd k r h xs #

Enum r => Enum (BitProd k r h xs) # 

Methods

succ :: BitProd k r h xs -> BitProd k r h xs #

pred :: BitProd k r h xs -> BitProd k r h xs #

toEnum :: Int -> BitProd k r h xs #

fromEnum :: BitProd k r h xs -> Int #

enumFrom :: BitProd k r h xs -> [BitProd k r h xs] #

enumFromThen :: BitProd k r h xs -> BitProd k r h xs -> [BitProd k r h xs] #

enumFromTo :: BitProd k r h xs -> BitProd k r h xs -> [BitProd k r h xs] #

enumFromThenTo :: BitProd k r h xs -> BitProd k r h xs -> BitProd k r h xs -> [BitProd k r h xs] #

Eq r => Eq (BitProd k r h xs) # 

Methods

(==) :: BitProd k r h xs -> BitProd k r h xs -> Bool #

(/=) :: BitProd k r h xs -> BitProd k r h xs -> Bool #

Ord r => Ord (BitProd k r h xs) # 

Methods

compare :: BitProd k r h xs -> BitProd k r h xs -> Ordering #

(<) :: BitProd k r h xs -> BitProd k r h xs -> Bool #

(<=) :: BitProd k r h xs -> BitProd k r h xs -> Bool #

(>) :: BitProd k r h xs -> BitProd k r h xs -> Bool #

(>=) :: BitProd k r h xs -> BitProd k r h xs -> Bool #

max :: BitProd k r h xs -> BitProd k r h xs -> BitProd k r h xs #

min :: BitProd k r h xs -> BitProd k r h xs -> BitProd k r h xs #

(Forall k (Instance1 * k Show h) xs, BitFields k r h xs) => Show (BitProd k r h xs) # 

Methods

showsPrec :: Int -> BitProd k r h xs -> ShowS #

show :: BitProd k r h xs -> String #

showList :: [BitProd k r h xs] -> ShowS #

Ix r => Ix (BitProd k r h xs) # 

Methods

range :: (BitProd k r h xs, BitProd k r h xs) -> [BitProd k r h xs] #

index :: (BitProd k r h xs, BitProd k r h xs) -> BitProd k r h xs -> Int #

unsafeIndex :: (BitProd k r h xs, BitProd k r h xs) -> BitProd k r h xs -> Int

inRange :: (BitProd k r h xs, BitProd k r h xs) -> BitProd k r h xs -> Bool #

rangeSize :: (BitProd k r h xs, BitProd k r h xs) -> Int #

unsafeRangeSize :: (BitProd k r h xs, BitProd k r h xs) -> Int

Generic (BitProd k r h xs) # 

Associated Types

type Rep (BitProd k r h xs) :: * -> * #

Methods

from :: BitProd k r h xs -> Rep (BitProd k r h xs) x #

to :: Rep (BitProd k r h xs) x -> BitProd k r h xs #

Hashable r => Hashable (BitProd k r h xs) # 

Methods

hashWithSalt :: Int -> BitProd k r h xs -> Int #

hash :: BitProd k r h xs -> Int #

Storable r => Storable (BitProd k r h xs) # 

Methods

sizeOf :: BitProd k r h xs -> Int #

alignment :: BitProd k r h xs -> Int #

peekElemOff :: Ptr (BitProd k r h xs) -> Int -> IO (BitProd k r h xs) #

pokeElemOff :: Ptr (BitProd k r h xs) -> Int -> BitProd k r h xs -> IO () #

peekByteOff :: Ptr b -> Int -> IO (BitProd k r h xs) #

pokeByteOff :: Ptr b -> Int -> BitProd k r h xs -> IO () #

peek :: Ptr (BitProd k r h xs) -> IO (BitProd k r h xs) #

poke :: Ptr (BitProd k r h xs) -> BitProd k r h xs -> IO () #

type ExtensibleConstr k (BitProd k r) h xs x # 
type ExtensibleConstr k (BitProd k r) h xs x = (BitFields k r h xs, FromBits r (h x))
type Rep (BitProd k r h xs) # 
type Rep (BitProd k r h xs) = D1 * (MetaData "BitProd" "Data.Extensible.Bits" "extensible-0.4.9-KSQEHeZmXIZ6wE0YuParPP" True) (C1 * (MetaCons "BitProd" PrefixI True) (S1 * (MetaSel (Just Symbol "unBitProd") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 * r)))
type BitWidth (BitProd k r h xs) # 
type BitWidth (BitProd k r h xs) = TotalBits k h xs

class (Bits r, KnownNat (BitWidth a)) => FromBits r a where #

Conversion between a value and a bit representation.

Instances of FromBits must satisfy the following laws:

fromBits (x `shiftL` W .|. toBits a) ≡ a
toBits a `shiftR` W == zeroBits

where W is the BitWidth.

Minimal complete definition

fromBits, toBits

Associated Types

type BitWidth a :: Nat #

Methods

fromBits :: r -> a #

toBits :: a -> r #

Instances

FromBits Word64 Bool # 

Associated Types

type BitWidth Bool :: Nat #

Methods

fromBits :: Word64 -> Bool #

toBits :: Bool -> Word64 #

FromBits Word64 Int8 # 

Associated Types

type BitWidth Int8 :: Nat #

Methods

fromBits :: Word64 -> Int8 #

toBits :: Int8 -> Word64 #

FromBits Word64 Int16 # 

Associated Types

type BitWidth Int16 :: Nat #

FromBits Word64 Int32 # 

Associated Types

type BitWidth Int32 :: Nat #

FromBits Word64 Word8 # 

Associated Types

type BitWidth Word8 :: Nat #

FromBits Word64 Word16 # 

Associated Types

type BitWidth Word16 :: Nat #

FromBits Word64 Word32 # 

Associated Types

type BitWidth Word32 :: Nat #

FromBits Word64 Word64 # 

Associated Types

type BitWidth Word64 :: Nat #

Bits r => FromBits r () # 

Associated Types

type BitWidth () :: Nat #

Methods

fromBits :: r -> () #

toBits :: () -> r #

FromBits r a => FromBits r (Identity a) # 

Associated Types

type BitWidth (Identity a) :: Nat #

Methods

fromBits :: r -> Identity a #

toBits :: Identity a -> r #

(FromBits r a, FromBits r b, (~) Nat n ((+) (BitWidth a) (BitWidth b)), (<=) n (BitWidth r), KnownNat n) => FromBits r (a, b) # 

Associated Types

type BitWidth (a, b) :: Nat #

Methods

fromBits :: r -> (a, b) #

toBits :: (a, b) -> r #

Bits r => FromBits r (Proxy k a) # 

Associated Types

type BitWidth (Proxy k a) :: Nat #

Methods

fromBits :: r -> Proxy k a #

toBits :: Proxy k a -> r #

FromBits r a => FromBits r (Const' k a b) # 

Associated Types

type BitWidth (Const' k a b) :: Nat #

Methods

fromBits :: r -> Const' k a b #

toBits :: Const' k a b -> r #

(Bits r, KnownNat (TotalBits k h xs)) => FromBits r (BitProd k r h xs) # 

Associated Types

type BitWidth (BitProd k r h xs) :: Nat #

Methods

fromBits :: r -> BitProd k r h xs #

toBits :: BitProd k r h xs -> r #

(Bits r, FromBits r (h (AssocValue k v x))) => FromBits r (Field k v h x) # 

Associated Types

type BitWidth (Field k v h x) :: Nat #

Methods

fromBits :: r -> Field k v h x #

toBits :: Field k v h x -> r #

type family TotalBits h xs where ... #

Total BitWidth

Equations

TotalBits h '[] = 0 
TotalBits h (x ': xs) = BitWidth (h x) + TotalBits h xs 

type BitFields r h xs = (FromBits r r, TotalBits h xs <= BitWidth r, Forall (Instance1 (FromBits r) h) xs) #

Fields are instances of FromBits and fit in the representation.

blookup :: forall x r h xs. (BitFields r h xs, FromBits r (h x)) => Membership xs x -> BitProd r h xs -> h x #

bupdate :: forall x r h xs. (BitFields r h xs, FromBits r (h x)) => Membership xs x -> BitProd r h xs -> h x -> BitProd r h xs #

Update a field of a BitProd.

toBitProd :: forall r h xs. BitFields r h xs => (h :* xs) -> BitProd r h xs #

Convert a normal extensible record into a bit record.

fromBitProd :: forall r h xs. BitFields r h xs => BitProd r h xs -> h :* xs #

Convert a normal extensible record into a bit record.

type BitRecordOf r h = BitProd r (Field h) #

Bit-packed record

type BitRecord r = BitRecordOf r Identity #

Bit-packed record