]> gitweb.michael.orlitzky.com - hath.git/blobdiff - src/Bit.hs
Added three new modules which are currently independent of the rest of the code:...
[hath.git] / src / Bit.hs
diff --git a/src/Bit.hs b/src/Bit.hs
new file mode 100644 (file)
index 0000000..1c7de7b
--- /dev/null
@@ -0,0 +1,15 @@
+module Bit where
+
+data Bit = Zero | One
+         deriving (Eq, Show)
+
+bit_to_int :: Bit -> Int
+bit_to_int Zero = 0
+bit_to_int One  = 1
+
+-- If we are passed a '0' or '1', convert it appropriately. Otherwise,
+-- default to Zero.
+bit_from_char :: Char -> Bit
+bit_from_char '0' = Zero
+bit_from_char '1' = One
+bit_from_char  _  = Zero