]> gitweb.michael.orlitzky.com - hath.git/blob - src/Bit.hs
Add more Haddock comments.
[hath.git] / src / Bit.hs
1 -- | The Bit module contains the Bit data type, which is essentially a
2 -- renamed Boolean, and some convenience functions.
3 module Bit
4 where
5
6 import Test.QuickCheck (
7 Arbitrary,
8 arbitrary,
9 elements
10 )
11
12
13 data Bit = Zero | One
14 deriving (Eq)
15
16 instance Show Bit where
17 show Zero = "0"
18 show One = "1"
19
20
21 instance Arbitrary Bit where
22 arbitrary = elements [ Zero, One ]
23
24
25 -- | Convert a Bit to an Int.
26 bit_to_int :: Bit -> Int
27 bit_to_int Zero = 0
28 bit_to_int One = 1
29
30 -- | If we are passed a '0' or '1', convert it
31 -- appropriately. Otherwise, return Nothing.
32 bit_from_char :: Char -> Maybe Bit
33 bit_from_char '0' = Just Zero
34 bit_from_char '1' = Just One
35 bit_from_char _ = Nothing