extensible-0.5: 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]) Source #

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 f p (BitProd r :: (k -> Type) -> [k] -> Type) Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type ExtensibleConstr (BitProd r) h xs x :: Constraint Source #

Methods

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

(Bits r, KnownNat (TotalBits h xs)) => FromBits r (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

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

Methods

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

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

Bounded r => Bounded (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

Methods

minBound :: BitProd r h xs #

maxBound :: BitProd r h xs #

Enum r => Enum (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

Methods

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

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

toEnum :: Int -> BitProd r h xs #

fromEnum :: BitProd r h xs -> Int #

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

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

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

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

Eq r => Eq (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

Methods

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

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

Ord r => Ord (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

Methods

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

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

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

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

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

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

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

(Forall (Instance1 Show h) xs, BitFields r h xs) => Show (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

Methods

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

show :: BitProd r h xs -> String #

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

Ix r => Ix (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

Methods

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

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

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

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

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

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

Generic (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

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

Methods

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

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

Hashable r => Hashable (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

Methods

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

hash :: BitProd r h xs -> Int #

Storable r => Storable (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

Methods

sizeOf :: BitProd r h xs -> Int #

alignment :: BitProd r h xs -> Int #

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

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

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

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

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

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

type ExtensibleConstr (BitProd r :: (k -> Type) -> [k] -> Type) (h :: k -> Type) (xs :: [k]) (x :: k) Source # 
Instance details

Defined in Data.Extensible.Bits

type ExtensibleConstr (BitProd r :: (k -> Type) -> [k] -> Type) (h :: k -> Type) (xs :: [k]) (x :: k) = (BitFields r h xs, FromBits r (h x))
type Rep (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

type Rep (BitProd r h xs) = D1 (MetaData "BitProd" "Data.Extensible.Bits" "extensible-0.5-HtYa3fOZlWC7KXWLoStAWc" True) (C1 (MetaCons "BitProd" PrefixI True) (S1 (MetaSel (Just "unBitProd") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 r)))
type BitWidth (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

type BitWidth (BitProd r h xs) = TotalBits h xs

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

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.

Associated Types

type BitWidth a :: Nat Source #

Methods

fromBits :: r -> a Source #

toBits :: a -> r Source #

Instances
FromBits Word64 Bool Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth Bool :: Nat Source #

FromBits Word64 Int8 Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth Int8 :: Nat Source #

FromBits Word64 Int16 Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth Int16 :: Nat Source #

FromBits Word64 Int32 Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth Int32 :: Nat Source #

FromBits Word64 Word8 Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth Word8 :: Nat Source #

FromBits Word64 Word16 Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth Word16 :: Nat Source #

FromBits Word64 Word32 Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth Word32 :: Nat Source #

FromBits Word64 Word64 Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth Word64 :: Nat Source #

Bits r => FromBits r () Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth () :: Nat Source #

Methods

fromBits :: r -> () Source #

toBits :: () -> r Source #

FromBits r a => FromBits r (Identity a) Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth (Identity a) :: Nat Source #

Methods

fromBits :: r -> Identity a Source #

toBits :: Identity a -> r Source #

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

Defined in Data.Extensible.Bits

Associated Types

type BitWidth (a, b) :: Nat Source #

Methods

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

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

Bits r => FromBits r (Proxy a) Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth (Proxy a) :: Nat Source #

Methods

fromBits :: r -> Proxy a Source #

toBits :: Proxy a -> r Source #

FromBits r a => FromBits r (Const a b) Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth (Const a b) :: Nat Source #

Methods

fromBits :: r -> Const a b Source #

toBits :: Const a b -> r Source #

(Bits r, KnownNat (TotalBits h xs)) => FromBits r (BitProd r h xs) Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

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

Methods

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

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

(Bits r, FromBits r (h (AssocValue x))) => FromBits r (Field h x) Source # 
Instance details

Defined in Data.Extensible.Bits

Associated Types

type BitWidth (Field h x) :: Nat Source #

Methods

fromBits :: r -> Field h x Source #

toBits :: Field h x -> r Source #

type family TotalBits h xs where ... Source #

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) Source #

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 Source #

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 Source #

Update a field of a BitProd.

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

Convert a normal extensible record into a bit record.

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

Convert a normal extensible record into a bit record.

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

Bit-packed record

type BitRecord r = BitRecordOf r Identity Source #

Bit-packed record