File: Bit.hs

package info (click to toggle)
haskell-http2 5.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 55,180 kB
  • sloc: haskell: 8,657; makefile: 5
file content (32 lines) | stat: -rw-r--r-- 508 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Network.HPACK.Huffman.Bit (
    -- * Bits
    B (..),
    Bits,
    fromBits,
) where

import Imports

-- | Data type for Bit.
data B
    = -- | Zero
      F
    | -- | One
      T
    deriving (Eq, Ord, Show)

-- | Bit stream.
type Bits = [B]

fromBit :: B -> Word8
fromBit F = 0
fromBit T = 1

-- | From 'Bits' of length 8 to 'Word8'.
--
-- >>> fromBits [T,F,T,F,T,F,T,F]
-- 170
-- >>> fromBits [F,T,F,T,F,T,F,T]
-- 85
fromBits :: Bits -> Word8
fromBits = foldl' (\x y -> x * 2 + y) 0 . map fromBit