| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Language.Hasmtlib.Type.Bitvec
Description
This module provides the type-level length-indexed and MSB-first bitvector Bitvec
built on top of the package bitvec and Vector.
It also holds it's type of encoding as a phantom-type via BvEnc.
Examples
>>>minBound @(Bitvec Unsigned 8)00000000
>>>maxBound @(Bitvec Signed 8)01111111
>>>(5 :: Bitvec Unsigned 4) + 101111
Synopsis
- data BvEnc
- data SBvEnc (enc :: BvEnc) where
- class KnownBvEnc (enc :: BvEnc) where
- bvEncSing' :: forall enc prxy. KnownBvEnc enc => prxy enc -> SBvEnc enc
- bvEncSing'' :: forall enc a prxy. KnownBvEnc enc => prxy enc a -> SBvEnc enc
- newtype Bitvec (enc :: BvEnc) (n :: Nat) = Bitvec {}
- bitvecConcat :: Bitvec enc n -> Bitvec enc m -> Bitvec enc (n + m)
- asUnsigned :: forall enc n. Bitvec enc n -> Bitvec Unsigned n
- asSigned :: forall enc n. Bitvec enc n -> Bitvec Signed n
- bitvecFromListN :: forall n enc. KnownNat n => [Bit] -> Maybe (Bitvec enc n)
- bitvecFromListN' :: KnownNat n => Proxy n -> [Bit] -> Maybe (Bitvec enc n)
- _signBit :: KnownNat (n + 1) => Lens' (Bitvec Signed (n + 1)) Bit
Bitvector encoding
Type of Bitvector encoding - used as promoted type (data-kind).
data SBvEnc (enc :: BvEnc) where Source #
Singleton for BvEnc.
Instances
| GCompare SBvEnc Source # | |
| GEq SBvEnc Source # | |
| Show (SBvEnc enc) Source # | |
| Eq (SBvEnc enc) Source # | |
| Ord (SBvEnc enc) Source # | |
Defined in Language.Hasmtlib.Type.Bitvec | |
class KnownBvEnc (enc :: BvEnc) where Source #
Instances
bvEncSing' :: forall enc prxy. KnownBvEnc enc => prxy enc -> SBvEnc enc Source #
bvEncSing'' :: forall enc a prxy. KnownBvEnc enc => prxy enc a -> SBvEnc enc Source #
Bitvec type
newtype Bitvec (enc :: BvEnc) (n :: Nat) Source #
Length-indexed bitvector (Vector) carrying a phantom type-level BvEnc.
Most significant bit is first (index 0) for unsigned bitvectors. Signed bitvectors have their sign bit first (index 0) and their most significant bit second (index 1).
Instances
Construction
bitvecConcat :: Bitvec enc n -> Bitvec enc m -> Bitvec enc (n + m) Source #
Concatenation of two bitvectors.
Conversion
Sign
Lists
bitvecFromListN :: forall n enc. KnownNat n => [Bit] -> Maybe (Bitvec enc n) Source #
Constructing a bitvector from a list.
bitvecFromListN' :: KnownNat n => Proxy n -> [Bit] -> Maybe (Bitvec enc n) Source #
Constructing a bitvector from a list with length given as Proxy.