@@ -4,41 +4,41 @@ import Parity
44import System
55
66data Bit : Nat -> Type where
7− b0 : Bit Z
8− b1 : Bit (S Z)
7+ B0 : Bit Z
8+ B1 : Bit (S Z)
99
1010instance Show (Bit n) where
1111 show = show' where
1212 show' : Bit x -> String
13− show' b0 = "0"
14− show' b1 = "1"
13+ show' B0 = "0"
14+ show' B1 = "1"
1515
1616infixl 5 #
1717
1818data Binary : (width : Nat) -> (value : Nat) -> Type where
19− zero : Binary Z Z
19+ Zero : Binary Z Z
2020 (#) : Binary w v -> Bit bit -> Binary (S w) (bit + 2 * v)
2121
2222instance Show (Binary w k) where
23− show zero = ""
23+ show Zero = ""
2424 show (bin # bit) = show bin ++ show bit
2525
2626pad : Binary w n -> Binary (S w) n
27−pad zero = zero # b0
27+pad Zero = Zero # B0
2828pad (num # x) = pad num # x
2929
3030natToBin : (width : Nat) -> (n : Nat) ->
3131 Maybe (Binary width n)
3232natToBin Z (S k) = Nothing
33−natToBin Z Z = Just zero
33+natToBin Z Z = Just Zero
3434natToBin (S k) Z = do x <- natToBin k Z
3535 Just (pad x)
3636natToBin (S w) (S k) with (parity k)
37− natToBin (S w) (S (plus j j)) | even = do jbin <- natToBin w j
38− let value = jbin # b1
37+ natToBin (S w) (S (plus j j)) | Even = do jbin <- natToBin w j
38+ let value = jbin # B1
3939 ?ntbEven
40− natToBin (S w) (S (S (plus j j))) | odd = do jbin <- natToBin w (S j)
41− let value = jbin # b0
40+ natToBin (S w) (S (S (plus j j))) | Odd = do jbin <- natToBin w (S j)
41+ let value = jbin # B0
4242 ?ntbOdd
4343
4444testBin : Maybe (Binary 8 42)
@@ -49,17 +49,17 @@ term syntax bitpair [x] [y] = (_ ** (_ ** (x, y, Refl)))
4949
5050addBit : Bit x -> Bit y -> Bit c ->
5151 (bX ** (bY ** (Bit bX, Bit bY, c + x + y = bY + 2 * bX)))
52−addBit b0 b0 b0 = bitpair b0 b0
53−addBit b0 b0 b1 = bitpair b0 b1
54−addBit b0 b1 b0 = bitpair b0 b1
55−addBit b0 b1 b1 = bitpair b1 b0
56−addBit b1 b0 b0 = bitpair b0 b1
57−addBit b1 b0 b1 = bitpair b1 b0
58−addBit b1 b1 b0 = bitpair b1 b0
59−addBit b1 b1 b1 = bitpair b1 b1
52+addBit B0 B0 B0 = bitpair B0 B0
53+addBit B0 B0 B1 = bitpair B0 B1
54+addBit B0 B1 B0 = bitpair B0 B1
55+addBit B0 B1 B1 = bitpair B1 B0
56+addBit B1 B0 B0 = bitpair B0 B1
57+addBit B1 B0 B1 = bitpair B1 B0
58+addBit B1 B1 B0 = bitpair B1 B0
59+addBit B1 B1 B1 = bitpair B1 B1
6060
6161adc : Binary w x -> Binary w y -> Bit c -> Binary (S w) (c + x + y)
62−adc zero zero carry ?= zero # carry
62+adc Zero Zero carry ?= Zero # carry
6363adc (numx # bX) (numy # bY) carry
6464 ?= let (bitpair carry0 lsb) = addBit bX bY carry in
6565 adc numx numy carry0 # lsb
@@ -75,7 +75,7 @@ main = do let Just bin1 = natToBin 8 42
7575 printLn bin1
7676 let Just bin2 = natToBin 8 89
7777 printLn bin2
78− printLn (adc bin1 bin2 b0)
78+ printLn (adc bin1 bin2 B0)
7979
8080
8181