-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Haskus binary format manipulation -- -- A set of types and tools to manipulate binary data, memory, etc. In -- particular to interface Haskell data types with foreign data types (C -- structs, unions, enums, etc.). @package haskus-binary @version 0.6.0.0 -- | Unsigned and signed words module Haskus.Format.Binary.Word -- | 8-bit signed integer type data Int8 :: * -- | 16-bit signed integer type data Int16 :: * -- | 32-bit signed integer type data Int32 :: * -- | 64-bit signed integer type data Int64 :: * -- | Bit size -- | Return a Word with at least n bits -- | Haskell type representing the C size_t type. newtype CSize :: * CSize :: Word64 -> CSize -- | Haskell type representing the C unsigned short type. data CUShort :: * -- | Haskell type representing the C short type. data CShort :: * -- | Haskell type representing the C unsigned int type. data CUInt :: * -- | Haskell type representing the C int type. data CInt :: * -- | Haskell type representing the C unsigned long type. data CULong :: * -- | Haskell type representing the C long type. data CLong :: * data Word# :: TYPE WordRep data Int# :: TYPE IntRep plusWord# :: Word# -> Word# -> Word# minusWord# :: Word# -> Word# -> Word# (+#) :: Int# -> Int# -> Int# infixl 6 +# (-#) :: Int# -> Int# -> Int# infixl 6 -# (==#) :: Int# -> Int# -> Int# infix 4 ==# (>#) :: Int# -> Int# -> Int# infix 4 ># (<#) :: Int# -> Int# -> Int# infix 4 <# (>=#) :: Int# -> Int# -> Int# infix 4 >=# (<=#) :: Int# -> Int# -> Int# infix 4 <=# ltWord# :: Word# -> Word# -> Int# leWord# :: Word# -> Word# -> Int# gtWord# :: Word# -> Word# -> Int# geWord# :: Word# -> Word# -> Int# eqWord# :: Word# -> Word# -> Int# -- | Alias for tagToEnum#. Returns True if its parameter is 1# and -- False if it is 0#. isTrue# :: Int# -> Bool -- | Memory layout -- -- Describe a memory region module Haskus.Format.Binary.Layout -- | Type obtained when following path p -- | Offset obtained when following path p type LayoutRoot = LayoutPath '[] -- | Path in a layout data LayoutPath (path :: [*]) LayoutPath :: LayoutPath -- | Index in a layout path data LayoutIndex (n :: Nat) LayoutIndex :: LayoutIndex -- | Symbol in a layout path data LayoutSymbol (s :: Symbol) LayoutSymbol :: LayoutSymbol -- | Index in the layout path layoutIndex :: forall n. LayoutPath '[LayoutIndex n] -- | Symbol in the layout path layoutSymbol :: forall s. LayoutPath '[LayoutSymbol s] -- | Pointers -- -- A pointer is a number: an offset into a memory. This is the `Addr#` -- type. -- -- We want the type-system to help us avoid errors when we use pointers, -- hence we decorate them with phantom types describing the memory layout -- at the pointed address. This is the `Ptr a` data type that wraps an -- `Addr#`. -- -- We often want to associate finalizers to pointers, i.e., actions to be -- run when the pointer is collected by the GC. These actions take the -- pointer as a parameter. This is the `ForeignPtr a` data type. -- -- A `ForeignPtr a` cannot be manipulated like a number because somehow -- we need to keep the pointer value that will be passed to the -- finalizers. Moreover we don't want finalizers to be executed too -- early, so we can't easily create a new ForeignPtr from another (it -- would require a way to disable the existing finalizers of a -- ForeignPtr, which would in turn open a whole can of worms). Hence we -- use the `FinalizedPtr a` pointer type, which has an additional offset -- field. module Haskus.Format.Binary.Ptr -- | Pointer operations class PtrLike (p :: * -> *) where castPtr = unsafeCoerce indexField p _ = castPtr (p `indexPtr` natValue @(LayoutPathOffset l path)) (-->) l _ = indexField l (layoutSymbol :: LayoutPath '[LayoutSymbol s]) (-#>) l _ = indexField l (layoutIndex :: LayoutPath '[LayoutIndex n]) -- | Cast a pointer from one type to another castPtr :: PtrLike p => p a -> p b -- | Null pointer (offset is 0) nullPtr :: forall a. PtrLike p => p a -- | Advance a pointer by the given amount of bytes (may be negative) indexPtr :: PtrLike p => p a -> Int -> p a -- | Distance between two pointers in bytes (p2 - p1) ptrDistance :: PtrLike p => p a -> p b -> Int -- | Use the pointer withPtr :: PtrLike p => p a -> (Ptr a -> IO b) -> IO b -- | Malloc the given number of bytes mallocBytes :: (PtrLike p, MonadIO m) => Word -> m (p a) -- | Add offset to the given layout field indexField :: forall path l. (PtrLike p, KnownNat (LayoutPathOffset l path)) => p l -> path -> p (LayoutPathType l path) -- | Add offset corresponding to the layout field with the given symbol (-->) :: forall s l. (PtrLike p, KnownNat (LayoutPathOffset l (LayoutPath '[LayoutSymbol s]))) => p l -> LayoutSymbol s -> p (LayoutPathType l (LayoutPath '[LayoutSymbol s])) -- | Add offset corresponding to the layout field with the given index (-#>) :: forall n l. (PtrLike p, KnownNat (LayoutPathOffset l (LayoutPath '[LayoutIndex n]))) => p l -> LayoutIndex n -> p (LayoutPathType l (LayoutPath '[LayoutIndex n])) -- | Generalized version of indexPtr indexPtr' :: Integral b => Ptr a -> b -> Ptr a -- | A value of type Ptr a represents a pointer to an -- object, or an array of objects, which may be marshalled to or from -- Haskell values of type a. -- -- The type a will often be an instance of class Storable -- which provides the marshalling operations. However this is not -- essential, and you can provide your own operations to access the -- pointer. For example you might write small foreign functions to get or -- set the fields of a C struct. data Ptr a :: * -> * Ptr :: Addr# -> Ptr a -- | Free a malloced memory free :: MonadIO m => Ptr a -> m () -- | A finalized pointer -- -- We use an offset because we can't modify the pointer directly (it is -- passed to the foreign pointer destructors) data FinalizedPtr l FinalizedPtr :: {-# UNPACK #-} !(ForeignPtr l) -> {-# UNPACK #-} !Word -> FinalizedPtr l -- | Use a finalized pointer withFinalizedPtr :: FinalizedPtr a -> (Ptr a -> IO b) -> IO b -- | The type ForeignPtr represents references to objects that are -- maintained in a foreign language, i.e., that are not part of the data -- structures usually managed by the Haskell storage manager. The -- essential difference between ForeignPtrs and vanilla memory -- references of type Ptr a is that the former may be associated -- with finalizers. A finalizer is a routine that is invoked when -- the Haskell storage manager detects that - within the Haskell heap and -- stack - there are no more references left that are pointing to the -- ForeignPtr. Typically, the finalizer will, then, invoke -- routines in the foreign language that free the resources bound by the -- foreign object. -- -- The ForeignPtr is parameterised in the same way as Ptr. -- The type argument of ForeignPtr should normally be an instance -- of class Storable. data ForeignPtr a :: * -> * -- | Use a foreign pointer withForeignPtr :: (MonadInIO m) => ForeignPtr a -> (Ptr a -> m b) -> m b -- | Malloc a foreign pointer mallocForeignPtrBytes :: MonadIO m => Word -> m (ForeignPtr a) -- | Null foreign pointer nullForeignPtr :: ForeignPtr a -- | A value of type FunPtr a is a pointer to a function -- callable from foreign code. The type a will normally be a -- foreign type, a function type with zero or more arguments where -- --
-- foreign import ccall "stdlib.h &free" -- p_free :: FunPtr (Ptr a -> IO ()) ---- -- or a pointer to a Haskell function created using a wrapper stub -- declared to produce a FunPtr of the correct type. For example: -- --
-- type Compare = Int -> Int -> Bool -- foreign import ccall "wrapper" -- mkCompare :: Compare -> IO (FunPtr Compare) ---- -- Calls to wrapper stubs like mkCompare allocate storage, which -- should be released with freeHaskellFunPtr when no longer -- required. -- -- To convert FunPtr values to corresponding Haskell functions, -- one can define a dynamic stub for the specific foreign type, -- e.g. -- --
-- type IntFunction = CInt -> IO () -- foreign import ccall "dynamic" -- mkFun :: FunPtr IntFunction -> IntFunction --data FunPtr a :: * -> * -- | The constant nullFunPtr contains a distinguished value of -- FunPtr that is not associated with a valid memory location. nullFunPtr :: FunPtr a -- | Casts a Ptr to a FunPtr. -- -- Note: this is valid only on architectures where data and -- function pointers range over the same set of addresses, and should -- only be used for bindings to external libraries whose interface -- already relies on this assumption. castPtrToFunPtr :: Ptr a -> FunPtr b -- | Casts a FunPtr to a Ptr. -- -- Note: this is valid only on architectures where data and -- function pointers range over the same set of addresses, and should -- only be used for bindings to external libraries whose interface -- already relies on this assumption. castFunPtrToPtr :: FunPtr a -> Ptr b -- | An unsigned integral type that can be losslessly converted to and from -- Ptr. This type is also compatible with the C99 type -- uintptr_t, and can be marshalled to and from that type -- safely. data WordPtr :: * -- | casts a WordPtr to a Ptr wordPtrToPtr :: WordPtr -> Ptr a -- | casts a Ptr to a WordPtr ptrToWordPtr :: Ptr a -> WordPtr instance GHC.Show.Show (Haskus.Format.Binary.Ptr.FinalizedPtr l) instance Haskus.Format.Binary.Ptr.PtrLike GHC.Ptr.Ptr instance Haskus.Format.Binary.Ptr.PtrLike Haskus.Format.Binary.Ptr.FinalizedPtr -- | Storable class module Haskus.Format.Binary.Storable -- | A storable data in constant space whose size is known at compile time class StaticStorable a where type SizeOf a :: Nat type Alignment a :: Nat where { type family SizeOf a :: Nat; type family Alignment a :: Nat; } -- | Peek (read) a value from a memory address staticPeekIO :: StaticStorable a => Ptr a -> IO a -- | Poke (write) a value at the given memory address staticPokeIO :: StaticStorable a => Ptr a -> a -> IO () -- | Peek (read) a value from a memory address staticPeek :: (StaticStorable a, MonadIO m) => Ptr a -> m a -- | Poke (write) a value at the given memory address staticPoke :: (StaticStorable a, MonadIO m) => Ptr a -> a -> m () -- | Compute the required padding between a and b to respect b's alignment -- | Compute the required padding between the size sz and b to respect b's -- alignment -- | Get statically known size staticSizeOf :: forall a. (KnownNat (SizeOf a)) => a -> Word -- | Get statically known alignment staticAlignment :: forall a. (KnownNat (Alignment a)) => a -> Word -- | Get bytes in host-endianness order wordBytes :: forall a. (Storable a, KnownNat (SizeOf a)) => a -> [Word8] -- | Storable data-types -- -- Currently we cannot automatically derive a Storable class with -- type-level naturals for "alignment" and "sizeOf". Instead we define a -- Storable class isomorphic to the Foreign.Storable's one but with -- default methods using DefaultSignatures (i.e., the Storable instance -- can be automatically derived from a Generic instance). class Storable a where peekIO p = fmap to $ gcPeek 0 (castPtr p) pokeIO p x = gcPoke 0 (castPtr p) $ from x alignment = gcAlignment . from sizeOf = gcSizeOf 0 . from peekIO :: Storable a => Ptr a -> IO a peekIO :: (Storable a, Generic a, GStorable (Rep a)) => Ptr a -> IO a pokeIO :: Storable a => Ptr a -> a -> IO () pokeIO :: (Storable a, Generic a, GStorable (Rep a)) => Ptr a -> a -> IO () alignment :: Storable a => a -> Word alignment :: (Storable a, Generic a, GStorable (Rep a)) => a -> Word sizeOf :: Storable a => a -> Word sizeOf :: (Storable a, Generic a, GStorable (Rep a)) => a -> Word -- | Peek a value from a pointer peek :: (Storable a, MonadIO m) => Ptr a -> m a -- | Poke a value to a pointer poke :: (Storable a, MonadIO m) => Ptr a -> a -> m () -- | Generalized sizeOf sizeOf' :: (Integral b, Storable a) => a -> b -- | SizeOf (for type-application) sizeOfT :: forall a. (Storable a) => Word -- | SizeOf' (for type-application) sizeOfT' :: forall a b. (Storable a, Integral b) => b -- | Generalized alignment alignment' :: (Integral b, Storable a) => a -> b -- | Alignment (for type-application) alignmentT :: forall a. (Storable a) => Word -- | Alignment' (for type-application) alignmentT' :: forall a b. (Storable a, Integral b) => b -- | Peek with byte offset peekByteOff :: (MonadIO m, Storable a) => Ptr a -> Int -> m a -- | Poke with byte offset pokeByteOff :: (MonadIO m, Storable a) => Ptr a -> Int -> a -> m () -- | Peek with element size offset peekElemOff :: forall a m. (MonadIO m, Storable a) => Ptr a -> Int -> m a -- | Poke with element size offset pokeElemOff :: (MonadIO m, Storable a) => Ptr a -> Int -> a -> m () -- | alloca f executes the computation f, passing -- as argument a pointer to a temporarily allocated block of memory -- sufficient to hold values of type a. -- -- The memory is freed when f terminates (either normally or via -- an exception), so the pointer passed to f must not be -- used after this. alloca :: forall a b m. (MonadInIO m, Storable a) => (Ptr a -> m b) -> m b -- | Allocate some bytes allocaBytes :: MonadInIO m => Word -> (Ptr a -> m b) -> m b -- | Allocate some aligned bytes allocaBytesAligned :: MonadInIO m => Word -> Word -> (Ptr a -> m b) -> m b -- | Allocate a block of memory that is sufficient to hold values of type -- a. The size of the area allocated is determined by the -- sizeOf method from the instance of Storable for the -- appropriate type. -- -- The memory may be deallocated using free or -- finalizerFree when no longer required. malloc :: forall a m. (MonadIO m, Storable a) => m (Ptr a) -- | with val f executes the computation f, -- passing as argument a pointer to a temporarily allocated block of -- memory into which val has been marshalled (the combination of -- alloca and poke). -- -- The memory is freed when f terminates (either normally or via -- an exception), so the pointer passed to f must not be -- used after this. with :: (MonadInIO m, Storable a) => a -> (Ptr a -> m b) -> m b -- | Replicates a withXXX combinator over a list of objects, -- yielding a list of marshalled objects withMany :: (a -> (b -> res) -> res) -> [a] -> ([b] -> res) -> res -- | Temporarily allocate space for the given number of elements (like -- alloca, but for multiple elements). allocaArray :: forall a b m. (MonadInIO m, Storable a) => Word -> (Ptr a -> m b) -> m b -- | Allocate space for the given number of elements (like malloc, -- but for multiple elements). mallocArray :: forall a m. (MonadIO m, Storable a) => Word -> m (Ptr a) -- | Temporarily store a list of storable values in memory (like -- with, but for multiple elements). withArray :: (MonadInIO m, Storable a) => [a] -> (Ptr a -> m b) -> m b -- | Like withArray, but the action gets the number of values as an -- additional parameter withArrayLen :: (MonadInIO m, Storable a) => [a] -> (Word -> Ptr a -> m b) -> m b -- | Convert an array of given length into a Haskell list. The -- implementation is tail-recursive and so uses constant stack space. peekArray :: (MonadIO m, Storable a) => Word -> Ptr a -> m [a] -- | Write the list elements consecutive into memory pokeArray :: (MonadIO m, Storable a) => Ptr a -> [a] -> m () instance Haskus.Format.Binary.Storable.GStorable GHC.Generics.U1 instance (Haskus.Format.Binary.Storable.GStorable a, Haskus.Format.Binary.Storable.GStorable b) => Haskus.Format.Binary.Storable.GStorable (a GHC.Generics.:*: b) instance Haskus.Format.Binary.Storable.GStorable a => Haskus.Format.Binary.Storable.GStorable (GHC.Generics.M1 i c a) instance Haskus.Format.Binary.Storable.Storable a => Haskus.Format.Binary.Storable.GStorable (GHC.Generics.K1 i a) instance Haskus.Format.Binary.Storable.StaticStorable GHC.Word.Word8 instance Haskus.Format.Binary.Storable.StaticStorable GHC.Word.Word16 instance Haskus.Format.Binary.Storable.StaticStorable GHC.Word.Word32 instance Haskus.Format.Binary.Storable.StaticStorable GHC.Word.Word64 instance Haskus.Format.Binary.Storable.StaticStorable GHC.Int.Int8 instance Haskus.Format.Binary.Storable.StaticStorable GHC.Int.Int16 instance Haskus.Format.Binary.Storable.StaticStorable GHC.Int.Int32 instance Haskus.Format.Binary.Storable.StaticStorable GHC.Int.Int64 instance Haskus.Format.Binary.Storable.Storable GHC.Word.Word8 instance Haskus.Format.Binary.Storable.Storable GHC.Word.Word16 instance Haskus.Format.Binary.Storable.Storable GHC.Word.Word32 instance Haskus.Format.Binary.Storable.Storable GHC.Word.Word64 instance Haskus.Format.Binary.Storable.Storable GHC.Int.Int8 instance Haskus.Format.Binary.Storable.Storable GHC.Int.Int16 instance Haskus.Format.Binary.Storable.Storable GHC.Int.Int32 instance Haskus.Format.Binary.Storable.Storable GHC.Int.Int64 instance Haskus.Format.Binary.Storable.Storable GHC.Types.Float instance Haskus.Format.Binary.Storable.Storable GHC.Types.Double instance Haskus.Format.Binary.Storable.Storable GHC.Types.Char instance Haskus.Format.Binary.Storable.Storable GHC.Types.Word instance Haskus.Format.Binary.Storable.Storable GHC.Types.Int instance Haskus.Format.Binary.Storable.Storable (GHC.Ptr.Ptr a) instance Haskus.Format.Binary.Storable.Storable Foreign.C.Types.CSize instance Haskus.Format.Binary.Storable.Storable Foreign.C.Types.CChar instance Haskus.Format.Binary.Storable.Storable Foreign.C.Types.CULong instance Haskus.Format.Binary.Storable.Storable Foreign.C.Types.CLong instance Haskus.Format.Binary.Storable.Storable Foreign.C.Types.CUInt instance Haskus.Format.Binary.Storable.Storable Foreign.C.Types.CInt instance Haskus.Format.Binary.Storable.Storable Foreign.C.Types.CUShort instance Haskus.Format.Binary.Storable.Storable Foreign.C.Types.CShort instance Haskus.Format.Binary.Storable.Storable Foreign.Ptr.WordPtr -- | Memory utilities module Haskus.Utils.Memory -- | Copy memory memCopy :: MonadIO m => Ptr a -> Ptr b -> Word64 -> m () -- | Set memory memSet :: MonadIO m => Ptr a -> Word64 -> Word8 -> m () -- | Allocate several arrays allocaArrays :: (MonadInIO m, Storable s, Integral a) => [a] -> ([Ptr s] -> m b) -> m b -- | Peek several arrays peekArrays :: (MonadIO m, Storable s, Integral a) => [a] -> [Ptr s] -> m [[s]] -- | Poke several arrays pokeArrays :: (MonadIO m, Storable s) => [Ptr s] -> [[s]] -> m () -- | Allocate several arrays withArrays :: (MonadInIO m, Storable s) => [[s]] -> ([Ptr s] -> m b) -> m b -- | Execute f with a pointer to a or NULL withMaybeOrNull :: (Storable a, MonadInIO m) => Maybe a -> (Ptr a -> m b) -> m b -- | Record (similar to C struct) module Haskus.Format.Binary.Record -- | Record data Record (fields :: [*]) -- | Field data Field (name :: Symbol) typ -- | Get record size without the ending padding bytes -- | Modulo data Path (fs :: [Symbol]) -- | Get record size recordSize :: forall fs. (KnownNat (FullRecordSize fs)) => Record fs -> Word -- | Get record alignment recordAlignment :: forall fs. (KnownNat (RecordAlignment fs 1)) => Record fs -> Word -- | Get a field recordField :: forall (name :: Symbol) a fs. (KnownNat (FieldOffset name fs 0), a ~ FieldType name fs, StaticStorable a) => Record fs -> a -- | Get a field offset recordFieldOffset :: forall (name :: Symbol) fs. (KnownNat (FieldOffset name fs 0)) => Record fs -> Int -- | Get a field from its path recordFieldPath :: forall path a fs o. (o ~ FieldPathOffset fs path 0, a ~ FieldPathType fs path, KnownNat o, StaticStorable a) => Path path -> Record fs -> a -- | Get a field offset from its path recordFieldPathOffset :: forall path fs o. (o ~ FieldPathOffset fs path 0, KnownNat o) => Path path -> Record fs -> Int -- | Convert a record into a HList recordToList :: forall fs. (HFoldr' Extract (Record fs, HList '[]) fs (Record fs, HList fs)) => Record fs -> HList fs instance (s ~ Haskus.Format.Binary.Record.FullRecordSize fs, GHC.TypeLits.KnownNat s) => Haskus.Format.Binary.Storable.StaticStorable (Haskus.Format.Binary.Record.Record fs) instance (rec ~ Haskus.Format.Binary.Record.Record fs, b ~ Haskus.Format.Binary.Record.Field name typ, i ~ (rec, Haskus.Utils.HList.HList l2), typ ~ Haskus.Format.Binary.Record.FieldType name fs, GHC.TypeLits.KnownNat (Haskus.Format.Binary.Record.FieldOffset name fs 0), Haskus.Format.Binary.Storable.StaticStorable typ, GHC.TypeLits.KnownSymbol name, r ~ (rec, Haskus.Utils.HList.HList ((GHC.Base.String, typ) : l2))) => Haskus.Utils.HList.Apply Haskus.Format.Binary.Record.Extract (b, i) r instance (Haskus.Utils.HList.HFoldr' Haskus.Format.Binary.Record.Extract (Haskus.Format.Binary.Record.Record fs, Haskus.Utils.HList.HList '[]) fs (Haskus.Format.Binary.Record.Record fs, Haskus.Utils.HList.HList fs), GHC.Show.Show (Haskus.Utils.HList.HList fs)) => GHC.Show.Show (Haskus.Format.Binary.Record.Record fs) -- | Union (as in C) -- -- Unions are storable and can contain any storable data. -- -- Use fromUnion to read a alternative: -- --
-- {--}
--
-- getUnion :: IO (Union '[Word16, Word32, Word64])
-- getUnion = ...
--
-- test = do
-- u <- getUnion
--
-- -- to get one of the member
-- let v = fromUnion u :: Word16
-- let v = fromUnion u :: Word32
-- let v = fromUnion u :: Word64
--
-- -- This won't compile (Word8 is not a member of the union)
-- let v = fromUnion u :: Word8
--
--
-- Use toUnion to create a new union: @
--
-- let u2 :: Union '[Word32, Vector 4 Word8] u2 = toUnion (0x12345678 ::
-- Word32) @
module Haskus.Format.Binary.Union
-- | An union
--
-- We use a list of types as a parameter.
--
-- The union is just a pointer to a buffer containing the value(s). The
-- size of the buffer is implicitly known from the types in the list.
data Union (x :: [*])
-- | Retrieve a union member from its type
fromUnion :: (Storable a, IsMember a l ~ True) => Union l -> a
-- | Create a new union from one of the union types
toUnion :: forall a l. (Storable (Union l), Storable a, IsMember a l ~ True) => a -> Union l
-- | Like toUnion but set the remaining bytes to 0
toUnionZero :: forall a l. (Storable (Union l), Storable a, IsMember a l ~ True) => a -> Union l
instance GHC.Show.Show (Haskus.Format.Binary.Union.Union x)
instance (GHC.TypeLits.KnownNat (Haskus.Utils.Types.List.Max (Haskus.Format.Binary.Union.MapSizeOf fs)), GHC.TypeLits.KnownNat (Haskus.Utils.Types.List.Max (Haskus.Format.Binary.Union.MapAlignment fs))) => Haskus.Format.Binary.Storable.StaticStorable (Haskus.Format.Binary.Union.Union fs)
instance (r ~ GHC.Types.Word, Haskus.Format.Binary.Storable.Storable a) => Haskus.Utils.HList.Apply Haskus.Format.Binary.Union.FoldSizeOf (a, GHC.Types.Word) r
instance (r ~ GHC.Types.Word, Haskus.Format.Binary.Storable.Storable a) => Haskus.Utils.HList.Apply Haskus.Format.Binary.Union.FoldAlignment (a, GHC.Types.Word) r
instance (Haskus.Utils.HList.HFoldr' Haskus.Format.Binary.Union.FoldSizeOf GHC.Types.Word l GHC.Types.Word, Haskus.Utils.HList.HFoldr' Haskus.Format.Binary.Union.FoldAlignment GHC.Types.Word l GHC.Types.Word) => Haskus.Format.Binary.Storable.Storable (Haskus.Format.Binary.Union.Union l)
instance (Haskus.Utils.HList.HFoldr' Haskus.Format.Binary.Union.FoldSizeOf GHC.Types.Word l GHC.Types.Word, Haskus.Utils.HList.HFoldr' Haskus.Format.Binary.Union.FoldAlignment GHC.Types.Word l GHC.Types.Word) => Foreign.Storable.Storable (Haskus.Format.Binary.Union.Union l)
-- | Store an Enum in the given backing word type
module Haskus.Format.Binary.Enum
-- | Store enum a as a b
data EnumField b a
-- | By default, use fromEnumtoEnum to convert fromto an Integral.
--
-- But it can be overloaded to perform transformation before using
-- fromEnum/toEnum. E.g. if values are shifted by 1 compared to Enum
-- values, define fromCEnum = (+1) . fromIntegral . fromEnum
class CEnum a where fromCEnum = fromIntegral . fromEnum toCEnum = toEnum . fromIntegral
fromCEnum :: (CEnum a, Integral b) => a -> b
fromCEnum :: (CEnum a, Enum a, Integral b) => a -> b
toCEnum :: (CEnum a, Integral b) => b -> a
toCEnum :: (CEnum a, Enum a, Integral b) => b -> a
-- | Read an enum field
fromEnumField :: EnumField b a -> a
-- | Create an enum field
toEnumField :: a -> EnumField b a
-- | Make an enum from a number (0 indexed)
makeEnum :: forall a i. (Data a, Integral i) => i -> a
-- | Make an enum with the last constructor taking a parameter for the rest
-- of the range, but don't build the last constructor
--
-- E.g., data T = A | B | C | D Word8 makeEnumMaybe :: Int -> T
-- makeEnumMaybe x = case x of 0 -> Just A 1 -> Just B 2 -> Just
-- C n -> Nothing
makeEnumMaybe :: forall a i. (Data a, Integral i) => i -> Maybe a
-- | Make an enum with the last constructor taking a parameter for the rest
-- of the range
--
-- E.g., data T = A | B | C | D Word8 makeEnumWithCustom :: Int -> T
-- makeEnumWithCustom x = case x of 0 -> A 1 -> B 2 -> C n ->
-- D (n - 3)
makeEnumWithCustom :: forall a i. (Data a, Integral i) => i -> a
instance GHC.Classes.Eq a => GHC.Classes.Eq (Haskus.Format.Binary.Enum.EnumField b a)
instance GHC.Show.Show a => GHC.Show.Show (Haskus.Format.Binary.Enum.EnumField b a)
instance (Haskus.Format.Binary.Storable.Storable b, GHC.Real.Integral b, Haskus.Format.Binary.Enum.CEnum a) => Haskus.Format.Binary.Storable.Storable (Haskus.Format.Binary.Enum.EnumField b a)
instance (GHC.Real.Integral b, Haskus.Format.Binary.Storable.StaticStorable b, Haskus.Format.Binary.Enum.CEnum a) => Haskus.Format.Binary.Storable.StaticStorable (Haskus.Format.Binary.Enum.EnumField b a)
-- | Bit orderings
module Haskus.Format.Binary.Bits.Order
-- | Bit order
--
-- The first letter indicates the outer bit ordering, i.e. how bytes are
-- filled: B*: from left to right (B is for BigEndian) L*: from right to
-- left (L is for LittleEndian)
--
-- The second letter indicates the inner bit ordering, i.e. how words are
-- stored: *B: the most significant bit is stored first (in the outer bit
-- order!) *L: the least-significant bit is stored first (in the outer
-- bit order!)
--
-- E.g. two successive words of 5 bits: ABCDE, VWXYZ - BB: ABCDEVWX
-- YZxxxxxx - BL: EDCBAZYX WVxxxxxx - LB: XWVEDCBA xxxxxxZY - LL:
-- XYZABCDE xxxxxxVW
data BitOrder
BB :: BitOrder
LB :: BitOrder
BL :: BitOrder
LL :: BitOrder
instance GHC.Classes.Eq Haskus.Format.Binary.Bits.Order.BitOrder
instance GHC.Show.Show Haskus.Format.Binary.Bits.Order.BitOrder
-- | Basic operations on bits
module Haskus.Format.Binary.Bits.Basic
-- | A memory buffer with a fixed address
--
-- A buffer is a strict ByteString but with:
--
--
-- {--}
-- data Flag
-- = FlagXXX
-- | FlagYYY
-- | FlagWWW
-- deriving (Show,Eq,Enum,CBitSet)
--
-- -- Adapt the backing type, here we choose Word16
-- type Flags = BitSet Word16 Flag
--
--
-- Then you can convert (for free) a Word16 into Flags with
-- fromBits and convert back with toBits.
--
-- You can check if a flag is set or not with member and
-- notMember and get a list of set flags with toList. You
-- can insert or delete flags. You can also perform set
-- operations such as union and intersection.
module Haskus.Format.Binary.BitSet
-- | A bit set: use bitwise operations (fast!) and minimal storage (sizeOf
-- basetype)
--
-- b is the base type (Bits b) a is the element type (Enum a)
--
-- The elements in the Enum a are flags corresponding to each bit of b
-- starting from the least-significant bit.
data BitSet b a
-- | Bit set indexed with a
class CBitSet a where toBitOffset = fromEnum fromBitOffset = toEnum
-- | Return the bit offset of an element
toBitOffset :: CBitSet a => a -> Int
-- | Return the bit offset of an element
toBitOffset :: (CBitSet a, Enum a) => a -> Int
-- | Return the value associated with a bit offset
fromBitOffset :: CBitSet a => Int -> a
-- | Return the value associated with a bit offset
fromBitOffset :: (CBitSet a, Enum a) => Int -> a
-- | Indicate if the set is empty
null :: (FiniteBits b) => BitSet b a -> Bool
-- | Empty bitset
empty :: (FiniteBits b) => BitSet b a
-- | Create a BitSet from a single element
singleton :: (Bits b, CBitSet a) => a -> BitSet b a
-- | Insert an element in the set
insert :: (Bits b, CBitSet a) => BitSet b a -> a -> BitSet b a
-- | Remove an element from the set
delete :: (Bits b, CBitSet a) => BitSet b a -> a -> BitSet b a
-- | Unwrap the bitset
toBits :: BitSet b a -> b
-- | Wrap a bitset
fromBits :: (CBitSet a, FiniteBits b) => b -> BitSet b a
-- | Test if an element is in the set
member :: (CBitSet a, FiniteBits b) => BitSet b a -> a -> Bool
-- | Test if an element is in the set
elem :: (CBitSet a, FiniteBits b) => a -> BitSet b a -> Bool
-- | Test if an element is not in the set
notMember :: (CBitSet a, FiniteBits b) => BitSet b a -> a -> Bool
-- | Retrieve elements in the set
elems :: (CBitSet a, FiniteBits b) => BitSet b a -> [a]
-- | Intersection of two sets
intersection :: FiniteBits b => BitSet b a -> BitSet b a -> BitSet b a
-- | Intersection of two sets
union :: FiniteBits b => BitSet b a -> BitSet b a -> BitSet b a
-- | Intersection of several sets
unions :: FiniteBits b => [BitSet b a] -> BitSet b a
-- | Convert a list of enum elements into a bitset Warning: b must have
-- enough bits to store the given elements! (we don't perform any check,
-- for performance reason)
fromListToBits :: (CBitSet a, FiniteBits b, Foldable m) => m a -> b
-- | Convert a bitset into a list of Enum elements
toListFromBits :: (CBitSet a, FiniteBits b) => b -> [a]
-- | Convert a Foldable into a set
fromList :: (CBitSet a, FiniteBits b, Foldable m) => m a -> BitSet b a
-- | Convert a set into a list
toList :: (CBitSet a, FiniteBits b) => BitSet b a -> [a]
instance Haskus.Format.Binary.Storable.Storable b => Haskus.Format.Binary.Storable.Storable (Haskus.Format.Binary.BitSet.BitSet b a)
instance GHC.Classes.Ord b => GHC.Classes.Ord (Haskus.Format.Binary.BitSet.BitSet b a)
instance GHC.Classes.Eq b => GHC.Classes.Eq (Haskus.Format.Binary.BitSet.BitSet b a)
instance (GHC.Show.Show a, Haskus.Format.Binary.BitSet.CBitSet a, Data.Bits.FiniteBits b) => GHC.Show.Show (Haskus.Format.Binary.BitSet.BitSet b a)
instance Haskus.Format.Binary.BitSet.CBitSet GHC.Types.Int
instance (Data.Bits.FiniteBits b, Haskus.Format.Binary.BitSet.CBitSet a) => GHC.Exts.IsList (Haskus.Format.Binary.BitSet.BitSet b a)
-- | Bit fields (as in C)
--
-- This module allows you to define bit fields over words. For instance,
-- you can have a Word16 split into 3 fields X, Y and Z composed of 5, 9
-- and 2 bits respectively.
--
-- X Y Z w :: Word16 |0 0 0 0 0|0 0 0 0 0 0 0 0 0|0 0|
--
-- You define it as follows: @ {--}
--
-- w :: BitFields Word16 '[ BitField 5 X Word8 , BitField 9
-- Y Word16 , BitField 2 Z Word8 ] w = BitFields 0x0102 @
--
-- Note that each field has its own associated type (e.g. Word8 for X and
-- Z) that must be large enough to hold the number of bits for the field.
--
-- Operations on BitFields expect that the cumulated size of the fields
-- is equal to the whole word size: use a padding field if necessary.
-- Otherwise you can use unsafe versions of the functions: extractField',
-- updateField', withField'.
--
-- You can extract and update the value of a field by its name:
--
-- -- x = extractField X w -- z = extractField Z w -- w' = updateField @Y 0x16 w ---- -- Fields can also be BitSet or EnumField: @ {--} -- -- data A = A0 | A1 | A2 | A3 deriving (Enum,CEnum) -- -- data B = B0 | B1 deriving (Enum,CBitSet) -- -- w :: BitFields Word16 '[ BitField 5 X (EnumField Word8 A) , -- BitField 9 Y Word16 , BitField 2 Z (BitSet Word8 B) ] w -- = BitFields 0x0102 @ module Haskus.Format.Binary.BitField -- | Bit fields on a base type b newtype BitFields b (f :: [*]) BitFields :: b -> BitFields b -- | Get backing word bitFieldsBits :: BitFields b f -> b -- | A field of n bits newtype BitField (n :: Nat) (name :: Symbol) s BitField :: s -> BitField s -- | Get the value of a field extractField :: forall (name :: Symbol) fields b. (KnownNat (Offset name fields), KnownNat (Size name fields), WholeSize fields ~ BitSize b, Bits b, Integral b, Field (Output name fields)) => BitFields b fields -> Output name fields -- | Get the value of a field (without checking sizes) extractField' :: forall (name :: Symbol) fields b. (KnownNat (Offset name fields), KnownNat (Size name fields), Bits b, Integral b, Field (Output name fields)) => BitFields b fields -> Output name fields -- | Set the value of a field updateField :: forall name fields b. (KnownNat (Offset name fields), KnownNat (Size name fields), WholeSize fields ~ BitSize b, Bits b, Integral b, Field (Output name fields)) => Output name fields -> BitFields b fields -> BitFields b fields -- | Set the value of a field (without checking sizes) updateField' :: forall name fields b. (KnownNat (Offset name fields), KnownNat (Size name fields), Bits b, Integral b, Field (Output name fields)) => Output name fields -> BitFields b fields -> BitFields b fields -- | Modify the value of a field withField :: forall name fields b f. (KnownNat (Offset name fields), KnownNat (Size name fields), WholeSize fields ~ BitSize b, Bits b, Integral b, f ~ Output name fields, Field f) => (f -> f) -> BitFields b fields -> BitFields b fields -- | Modify the value of a field (without checking sizes) withField' :: forall (name :: Symbol) fields b f. (KnownNat (Offset name fields), KnownNat (Size name fields), Bits b, Integral b, f ~ Output name fields, Field f) => (f -> f) -> BitFields b fields -> BitFields b fields -- | Get values in a tuple matchFields :: forall l l2 w bs t. (bs ~ BitFields w l, HFoldr' Extract (bs, HList '[]) l (bs, HList l2), HTuple' l2 t) => bs -> t -- | Get field names and values in a tuple matchNamedFields :: forall lt lv ln lnv w bs t. (bs ~ BitFields w lt, HFoldr' Extract (bs, HList '[]) lt (bs, HList lv), HFoldr' Name (HList '[]) lt (HList ln), HZipList ln lv lnv, HTuple' lnv t) => bs -> t class Field f instance Haskus.Format.Binary.Storable.Storable s => Haskus.Format.Binary.Storable.Storable (Haskus.Format.Binary.BitField.BitField n name s) instance Haskus.Format.Binary.Storable.Storable b => Haskus.Format.Binary.Storable.Storable (Haskus.Format.Binary.BitField.BitFields b f) instance Haskus.Format.Binary.BitField.Field GHC.Types.Bool instance Haskus.Format.Binary.BitField.Field GHC.Types.Word instance Haskus.Format.Binary.BitField.Field GHC.Word.Word8 instance Haskus.Format.Binary.BitField.Field GHC.Word.Word16 instance Haskus.Format.Binary.BitField.Field GHC.Word.Word32 instance Haskus.Format.Binary.BitField.Field GHC.Word.Word64 instance Haskus.Format.Binary.BitField.Field GHC.Types.Int instance Haskus.Format.Binary.BitField.Field GHC.Int.Int8 instance Haskus.Format.Binary.BitField.Field GHC.Int.Int16 instance Haskus.Format.Binary.BitField.Field GHC.Int.Int32 instance Haskus.Format.Binary.BitField.Field GHC.Int.Int64 instance (Data.Bits.FiniteBits b, GHC.Real.Integral b, Haskus.Format.Binary.BitSet.CBitSet a) => Haskus.Format.Binary.BitField.Field (Haskus.Format.Binary.BitSet.BitSet b a) instance Haskus.Format.Binary.Enum.CEnum a => Haskus.Format.Binary.BitField.Field (Haskus.Format.Binary.Enum.EnumField b a) instance (bs ~ Haskus.Format.Binary.BitField.BitFields w l, b ~ Haskus.Format.Binary.BitField.BitField n name s, i ~ (bs, Haskus.Utils.HList.HList l2), r ~ (bs, Haskus.Utils.HList.HList (Haskus.Format.Binary.BitField.Output name l : l2)), Haskus.Format.Binary.Word.BitSize w ~ Haskus.Format.Binary.BitField.WholeSize l, GHC.Real.Integral w, Data.Bits.Bits w, GHC.TypeLits.KnownNat (Haskus.Format.Binary.BitField.Offset name l), GHC.TypeLits.KnownNat (Haskus.Format.Binary.BitField.Size name l), Haskus.Format.Binary.BitField.Field (Haskus.Format.Binary.BitField.Output name l)) => Haskus.Utils.HList.Apply Haskus.Format.Binary.BitField.Extract (b, i) r instance (bs ~ Haskus.Format.Binary.BitField.BitFields w l, b ~ Haskus.Format.Binary.BitField.BitField n name s, i ~ Haskus.Utils.HList.HList l2, r ~ Haskus.Utils.HList.HList (GHC.Base.String : l2), GHC.TypeLits.KnownSymbol name) => Haskus.Utils.HList.Apply Haskus.Format.Binary.BitField.Name (b, i) r instance (bs ~ Haskus.Format.Binary.BitField.BitFields w lt, ln ~ Haskus.Utils.Types.List.Replicate (Haskus.Utils.Types.List.Length lt) GHC.Base.String, Haskus.Utils.HList.HFoldr' Haskus.Format.Binary.BitField.Extract (bs, Haskus.Utils.HList.HList '[]) lt (bs, Haskus.Utils.HList.HList (Haskus.Format.Binary.BitField.BitFieldTypes lt)), Haskus.Utils.HList.HFoldr' Haskus.Format.Binary.BitField.Name (Haskus.Utils.HList.HList '[]) lt (Haskus.Utils.HList.HList ln), Haskus.Utils.HList.HZipList ln (Haskus.Format.Binary.BitField.BitFieldTypes lt) lnv, GHC.Show.Show (Haskus.Utils.HList.HList lnv)) => GHC.Show.Show (Haskus.Format.Binary.BitField.BitFields w lt) instance (bs ~ Haskus.Format.Binary.BitField.BitFields w lt, Haskus.Utils.HList.HFoldr' Haskus.Format.Binary.BitField.Extract (bs, Haskus.Utils.HList.HList '[]) lt (bs, Haskus.Utils.HList.HList lt2), GHC.Classes.Eq (Haskus.Utils.HList.HList lt2), lt2 ~ Haskus.Format.Binary.BitField.BitFieldTypes lt) => GHC.Classes.Eq (Haskus.Format.Binary.BitField.BitFields w lt) -- | Fixed-point numbers module Haskus.Format.Binary.FixedPoint -- | Fixed-point number w is the backing type i is the -- number of bits for the integer part (before the readix point) -- f is the number of bits for the fractional part (after the -- radix point) data FixedPoint w (i :: Nat) (f :: Nat) -- | Convert to a fixed point value toFixedPoint :: forall a w (n :: Nat) (d :: Nat). (RealFrac a, BitSize w ~ (n + d), KnownNat n, KnownNat d, Bits w, Field w, Num w, Integral w) => a -> FixedPoint w n d -- | Convert from a fixed-point value fromFixedPoint :: forall a w (n :: Nat) (d :: Nat). (RealFrac a, BitSize w ~ (n + d), KnownNat n, KnownNat d, Bits w, Field w, Num w, Integral w) => FixedPoint w n d -> a instance Haskus.Format.Binary.Storable.Storable w => Haskus.Format.Binary.Storable.Storable (Haskus.Format.Binary.FixedPoint.FixedPoint w i f) instance (GHC.Real.Integral w, Data.Bits.Bits w, Haskus.Format.Binary.BitField.Field w, Haskus.Format.Binary.Word.BitSize w ~ (n GHC.TypeLits.+ d), GHC.TypeLits.KnownNat n, GHC.TypeLits.KnownNat d) => GHC.Classes.Eq (Haskus.Format.Binary.FixedPoint.FixedPoint w n d) instance (GHC.Real.Integral w, Data.Bits.Bits w, Haskus.Format.Binary.BitField.Field w, Haskus.Format.Binary.Word.BitSize w ~ (n GHC.TypeLits.+ d), GHC.TypeLits.KnownNat n, GHC.TypeLits.KnownNat d, GHC.Show.Show w) => GHC.Show.Show (Haskus.Format.Binary.FixedPoint.FixedPoint w n d) module Haskus.Format.Binary.Unum -- | An Unum -- -- 0 (and its reciprocal) is always included. Numbers have to be >= 1 -- and sorted. -- -- e.g., Unum '[] => 0 .. 0 .. 0 Unum '[I 1] => 0 .. -1 -- .. 0 .. 1 .. 0 Unum '[I 1, I 2] => 0 .. -2 .. -1 .. -2 -- .. 0 .. 2 .. 1 .. 2 .. 0 Unum '[I 1, PI] => 0 .. -PI .. -- -1 .. -PI .. 0 .. PI .. 1 .. PI .. 0 data Unum (xs :: [*]) class UnumNum a unumLabel :: UnumNum a => a -> String data I (n :: Nat) newtype U u U :: (BackingWord u) -> U u data Neg a data Rcp a type Infinite = Rcp (I 0) -- | Compute the precise numbers set -- | Compute the number of bits required -- | Backing word for the unum -- | Uncertainty bit data UBit -- | Exact number ExactNumber :: UBit -- | OpenInterval above the exact number OpenInterval :: UBit -- | Size of an unum in bits unumSize :: forall u. (KnownNat (UnumSize u)) => Word -- | Zero unumZero :: forall u. (Num (BackingWord u), Bits (BackingWord u), Encodable (I 0) u) => U u -- | Infinite unumInfinite :: forall u. (Num (BackingWord u), Bits (BackingWord u), Encodable Infinite u) => U u -- | Encode a number unumEncode :: forall u x i. (i ~ IndexOf (Simplify x) (UnumIndexables u), KnownNat i, Num (BackingWord u), Bits (BackingWord u)) => UBit -> U u unumBits :: forall u. (FiniteBits (BackingWord u), KnownNat (UnumSize u)) => U u -> String -- | Negate a number unumNegate :: forall u. (FiniteBits (BackingWord u), Num (BackingWord u), KnownNat (UnumSize u)) => U u -> U u -- | Reciprocate a number unumReciprocate :: forall u. (FiniteBits (BackingWord u), Num (BackingWord u), KnownNat (UnumSize u)) => U u -> U u -- | Unum labels unumLabels :: forall u v. (HFoldr' GetLabel [String] v [String], v ~ UnumMembers u) => [String] data Sign Positive :: Sign Negative :: Sign NoSign :: Sign -- | Get unum sign unumSign :: forall u. (Bits (BackingWord u), KnownNat (UnumSize u)) => U u -> Sign data SORN u -- | Show SORN bits sornBits :: forall u s. (FiniteBits (SORNBackingWord u), KnownNat (UnumSize u), s ~ SORNSize u, KnownNat s) => SORN u -> String -- | Size of a SORN in bits sornSize :: forall u s. (s ~ SORNSize u, KnownNat s) => Word -- | Empty SORN sornEmpty :: (Bits (SORNBackingWord u)) => SORN u -- | Full SORN sornFull :: forall u. (FiniteBits (SORNBackingWord u), KnownNat (SORNSize u)) => SORN u -- | Full SORN without infinite sornNonInfinite :: forall u. (Bits (SORNBackingWord u), Integral (BackingWord u), Bits (BackingWord u), Encodable Infinite u) => SORN u -- | Full SORN without infinite sornNonZero :: (Bits (SORNBackingWord u), Integral (BackingWord u), Bits (BackingWord u), Encodable (I 0) u) => SORN u -- | SORN singleton sornSingle :: (Integral (BackingWord u), Bits (SORNBackingWord u)) => U u -> SORN u -- | Insert in a SORN sornInsert :: forall u. (Bits (SORNBackingWord u), Integral (BackingWord u)) => SORN u -> U u -> SORN u -- | Test membership in a SORN sornMember :: forall u. (Bits (SORNBackingWord u), Integral (BackingWord u)) => SORN u -> U u -> Bool -- | Remove in a SORN sornRemove :: forall u. (Bits (SORNBackingWord u), Integral (BackingWord u)) => SORN u -> U u -> SORN u -- | Union of two SORNs sornUnion :: forall u. (Bits (SORNBackingWord u)) => SORN u -> SORN u -> SORN u -- | Intersection of two SORNs sornIntersect :: forall u. (Bits (SORNBackingWord u)) => SORN u -> SORN u -> SORN u -- | Complement the SORN sornComplement :: (Bits (SORNBackingWord u)) => SORN u -> SORN u -- | Negate a SORN sornNegate :: forall u. (FiniteBits (SORNBackingWord u), FiniteBits (BackingWord u), Integral (BackingWord u), KnownNat (SORNSize u), KnownNat (UnumSize u)) => SORN u -> SORN u -- | Elements in the SORN sornElems :: forall u s. (s ~ SORNSize u, KnownNat s, Bits (SORNBackingWord u), Num (BackingWord u)) => SORN u -> [U u] -- | Create a SORN from its elements sornFromElems :: (Integral (BackingWord u), Bits (SORNBackingWord u)) => [U u] -> SORN u -- | Create a contiguous SORN from two elements sornFromTo :: forall u. (Integral (BackingWord u), Bits (SORNBackingWord u), FiniteBits (BackingWord u), KnownNat (UnumSize u)) => U u -> U u -> SORN u class SornAdd u where sornAdd a b = foldl sornUnion sornEmpty [sornAddU x y | x <- sornElems a, y <- sornElems b] sornAddDep a = foldl sornUnion sornEmpty [sornAddU x x | x <- sornElems a] sornSubU a b = sornAddU a (unumNegate b) sornSub a b = foldl sornUnion sornEmpty [sornSubU x y | x <- sornElems a, y <- sornElems b] sornSubDep a = foldl sornUnion sornEmpty [sornSubU x x | x <- sornElems a] -- | Add two Unums sornAddU :: SornAdd u => U u -> U u -> SORN u -- | Add two SORNs sornAdd :: (SornAdd u, KnownNat (SORNSize u), Bits (SORNBackingWord u), Num (BackingWord u)) => SORN u -> SORN u -> SORN u -- | Add a SORN with itself sornAddDep :: (SornAdd u, KnownNat (SORNSize u), Bits (SORNBackingWord u), Num (BackingWord u)) => SORN u -> SORN u -- | Subtract two Unums sornSubU :: (SornAdd u, FiniteBits (BackingWord u), Num (BackingWord u), KnownNat (UnumSize u)) => U u -> U u -> SORN u -- | Subtract two SORNS sornSub :: (SornAdd u, KnownNat (SORNSize u), Bits (SORNBackingWord u), FiniteBits (BackingWord u), Num (BackingWord u), KnownNat (UnumSize u)) => SORN u -> SORN u -> SORN u -- | Subtract a SORN with itself sornSubDep :: (SornAdd u, KnownNat (SORNSize u), Bits (SORNBackingWord u), FiniteBits (BackingWord u), Num (BackingWord u), KnownNat (UnumSize u)) => SORN u -> SORN u newtype CSORN u CSORN :: (BitFields (CSORNBackingWord u) '[BitField (UnumSize u) "start" (BackingWord u), BitField (UnumSize u) "count" (BackingWord u)]) -> CSORN u -- | Size of a contiguous SORN in bits csornSize :: forall u s. (s ~ CSORNSize u, KnownNat s) => Word -- | Show contiguous SORN bits csornBits :: forall u s. (FiniteBits (CSORNBackingWord u), KnownNat (UnumSize u), s ~ CSORNSize u, KnownNat s) => CSORN u -> String -- | Convert a contiguous SORN into a SORN csornToSorn :: forall u. (KnownNat (UnumSize u), Num (BackingWord u), Integral (BackingWord u), Integral (CSORNBackingWord u), Bits (CSORNBackingWord u), FiniteBits (BackingWord u), Bits (SORNBackingWord u), Field (BackingWord u), KnownNat (SORNSize u), FiniteBits (SORNBackingWord u)) => CSORN u -> SORN u -- | Empty contigiuous SORN csornEmpty :: forall u. (Bits (CSORNBackingWord u)) => CSORN u -- | Test if a contigiuous SORN is empty csornIsEmpty :: forall u. (Bits (CSORNBackingWord u)) => CSORN u -> Bool -- | Contiguous SORN build csornFromTo :: forall u. (Num (BackingWord u), Bits (BackingWord u), KnownNat (UnumSize u), KnownNat (SORNSize u), FiniteBits (BackingWord u), Integral (CSORNBackingWord u), Bits (CSORNBackingWord u), Field (BackingWord u), Integral (BackingWord u)) => U u -> U u -> CSORN u -- | Full contiguous SORN csornFull :: forall u. (Bits (CSORNBackingWord u), Integral (CSORNBackingWord u), Integral (BackingWord u), KnownNat (UnumSize u), Field (BackingWord u)) => CSORN u -- | Contiguous SORN singleton csornSingle :: forall u. (Bits (CSORNBackingWord u), Integral (CSORNBackingWord u), Integral (BackingWord u), KnownNat (UnumSize u), Field (BackingWord u)) => U u -> CSORN u instance GHC.Classes.Eq Haskus.Format.Binary.Unum.Sign instance GHC.Show.Show Haskus.Format.Binary.Unum.Sign instance GHC.Classes.Eq Haskus.Format.Binary.Unum.UBit instance GHC.Show.Show Haskus.Format.Binary.Unum.UBit instance GHC.TypeLits.KnownNat n => Haskus.Format.Binary.Unum.UnumNum (Haskus.Format.Binary.Unum.I n) instance Haskus.Format.Binary.Unum.UnumNum x => Haskus.Format.Binary.Unum.UnumNum (Haskus.Format.Binary.Unum.Rcp x) instance Haskus.Format.Binary.Unum.UnumNum x => Haskus.Format.Binary.Unum.UnumNum (Haskus.Format.Binary.Unum.Neg x) instance Haskus.Format.Binary.Unum.UnumNum x => Haskus.Format.Binary.Unum.UnumNum (Haskus.Format.Binary.Unum.Uncertain x) instance (Haskus.Format.Binary.Unum.UnumNum a, r ~ [GHC.Base.String]) => Haskus.Utils.HList.Apply Haskus.Format.Binary.Unum.GetLabel (a, [GHC.Base.String]) r instance GHC.Classes.Eq (Haskus.Format.Binary.Unum.BackingWord u) => GHC.Classes.Eq (Haskus.Format.Binary.Unum.U u) instance (Haskus.Utils.HList.HFoldr' Haskus.Format.Binary.Unum.GetLabel [GHC.Base.String] v [GHC.Base.String], v ~ Haskus.Format.Binary.Unum.UnumMembers u, GHC.Real.Integral (Haskus.Format.Binary.Unum.BackingWord u)) => GHC.Show.Show (Haskus.Format.Binary.Unum.U u) instance (GHC.TypeLits.KnownNat (Haskus.Format.Binary.Unum.SORNSize u), Data.Bits.Bits (Haskus.Format.Binary.Unum.SORNBackingWord u), GHC.Num.Num (Haskus.Format.Binary.Unum.BackingWord u), GHC.Real.Integral (Haskus.Format.Binary.Unum.BackingWord u), Haskus.Utils.HList.HFoldr' Haskus.Format.Binary.Unum.GetLabel [GHC.Base.String] v [GHC.Base.String], v ~ Haskus.Format.Binary.Unum.UnumMembers u) => GHC.Show.Show (Haskus.Format.Binary.Unum.SORN u) instance (GHC.TypeLits.KnownNat (Haskus.Format.Binary.Unum.SORNSize u), GHC.TypeLits.KnownNat (Haskus.Format.Binary.Unum.UnumSize u), Data.Bits.FiniteBits (Haskus.Format.Binary.Unum.BackingWord u), Data.Bits.Bits (Haskus.Format.Binary.Unum.CSORNBackingWord u), GHC.Real.Integral (Haskus.Format.Binary.Unum.CSORNBackingWord u), GHC.Num.Num (Haskus.Format.Binary.Unum.BackingWord u), GHC.Real.Integral (Haskus.Format.Binary.Unum.BackingWord u), Haskus.Utils.HList.HFoldr' Haskus.Format.Binary.Unum.GetLabel [GHC.Base.String] v [GHC.Base.String], Haskus.Format.Binary.BitField.Field (Haskus.Format.Binary.Unum.BackingWord u), Data.Bits.Bits (Haskus.Format.Binary.Unum.SORNBackingWord u), Data.Bits.FiniteBits (Haskus.Format.Binary.Unum.SORNBackingWord u), v ~ Haskus.Format.Binary.Unum.UnumMembers u) => GHC.Show.Show (Haskus.Format.Binary.Unum.CSORN u)