module Ersatz.BitChar where
import Data.Char (chr,ord)
import Control.Monad (liftM, replicateM)
import Prelude hiding ((&&))
import Data.Typeable (Typeable)
import Ersatz.Bit
import Ersatz.Bits
import Ersatz.Codec
import Ersatz.Equatable
import Ersatz.Orderable
import Ersatz.Variable
type BitString = [BitChar]
newtype BitChar = BitChar Bits
deriving (Show,Typeable)
instance Codec BitChar where
type Decoded BitChar = Char
encode = BitChar . fromIntegral . ord
decode s (BitChar xs) = liftM (chr . fromIntegral) (decode s xs)
instance Equatable BitChar where
BitChar xs === BitChar ys = xs === ys
BitChar xs /== BitChar ys = xs /== ys
instance Orderable BitChar where
BitChar xs <? BitChar ys = xs <? ys
BitChar xs <=? BitChar ys = xs <=? ys
instance Variable BitChar where
literally m =
do x:xs <- replicateM 21 (literally m)
let x' = x && nor (take 4 xs)
n = Bits (reverse (x':xs))
return (BitChar n)