Skip to content

Commit 5f75eb5

Browse files
pack should never raise XException
It can be nice to be able to rely on `pack` never raising `XException` and it is good behavior. I have always expected this behavior, but it was not documented. Let's document it. I have checked all instances in `clash-prelude` and they all conform to the law. The same goes for deriving a `BitPack` or using `deriveBitPack`.
1 parent ae0460f commit 5f75eb5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

clash-prelude/src/Clash/Class/BitPack/Internal.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class KnownNat (BitSize a) => BitPack a where
111111
type BitSize a = (CLog 2 (GConstructorCount (Rep a))) + (GFieldSize (Rep a))
112112
-- | Convert element of type @a@ to a 'BitVector'
113113
--
114+
-- @pack@ will never raise @XException@; as @BitVector@ is three-valued,
115+
-- @pack@ applied to an @XException@ will return a @BitVector@ filled with
116+
-- undefined bits.
117+
--
114118
-- >>> pack (-5 :: Signed 6)
115119
-- 0b11_1011
116120
pack :: a -> BitVector (BitSize a)

0 commit comments

Comments
 (0)