]> gitweb.michael.orlitzky.com - hath.git/blob - src/Bit.hs
Add a None constructor for Bits.
[hath.git] / src / Bit.hs
1 module Bit where
2
3 data Bit = None | Zero | One
4 deriving (Eq, Show)
5
6 bit_to_int :: Bit -> Int
7 bit_to_int None = -1
8 bit_to_int Zero = 0
9 bit_to_int One = 1
10
11 -- If we are passed a '0' or '1', convert it appropriately. Otherwise,
12 -- default to None.
13 bit_from_char :: Char -> Bit
14 bit_from_char '0' = Zero
15 bit_from_char '1' = One
16 bit_from_char _ = None