]> gitweb.michael.orlitzky.com - hath.git/blob - src/Bit.hs
Update for QuickCheck 2.
[hath.git] / src / Bit.hs
1 module Bit where
2
3 import Test.QuickCheck
4
5
6 data Bit = None | Zero | One
7 deriving (Eq)
8
9 instance Show Bit where
10 show None = "None"
11 show Zero = "0"
12 show One = "1"
13
14
15 instance Arbitrary Bit where
16 arbitrary = elements [ Zero, One ]
17
18
19 bit_to_int :: Bit -> Int
20 bit_to_int None = -1
21 bit_to_int Zero = 0
22 bit_to_int One = 1
23
24 -- If we are passed a '0' or '1', convert it appropriately. Otherwise,
25 -- default to None.
26 bit_from_char :: Char -> Bit
27 bit_from_char '0' = Zero
28 bit_from_char '1' = One
29 bit_from_char _ = None