Skip to content
This repository has been archived by the owner on Sep 7, 2018. It is now read-only.

Commit

Permalink
Update bv2i documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
christiaanb committed Oct 21, 2015
1 parent 1c2d853 commit 7311695
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/CLaSH/Sized/Index.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{-# LANGUAGE Trustworthy #-}

{-# OPTIONS_GHC -fplugin GHC.TypeLits.Extra.Solver #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_HADDOCK show-extensions #-}

{-|
Expand All @@ -18,9 +19,27 @@ module CLaSH.Sized.Index
where

import GHC.TypeLits (KnownNat, type (^))
import GHC.TypeLits.Extra (CLog) -- documentation only

import CLaSH.Sized.BitVector (BitVector)
import CLaSH.Sized.Internal.Index

-- | An alternative implementation of 'CLaSH.Class.BitPack.unpack' for the
-- 'Index' data type; for when you know the size of the 'BitVector' and want
-- to determine the size of the 'Index'.
--
-- That is, the type of 'CLaSH.Class.BitPack.unpack' is:
--
-- @
-- __unpack__ :: 'BitVector' ('CLog' 2 n) -> 'Index' n
-- @
--
-- And is useful when you know the size of the 'Index', and want to get a value
-- from a 'BitVector' that is large enough (@CLog 2 n@) enough to hold an
-- 'Index'. Note that 'CLaSH.Class.BitPack.unpack' can fail at /run-time/ when
-- the value inside the 'BitVector' is higher than 'n-1'.
--
-- 'bv2i' on the other hand will /never/ fail at run-time, because the
-- 'BitVector' argument determines the size.
bv2i :: KnownNat (2^n) => BitVector n -> Index (2^n)
bv2i = unpack#

0 comments on commit 7311695

Please sign in to comment.