+inv a = let r = hwnot a in r
+
+-- Not really an adder either, but a slightly more complex example
+invinv :: Bit -> Bit
+invinv a = hwnot (hwnot a)
+
+-- Not really an adder either, but a slightly more complex example
+dup :: Bit -> (Bit, Bit)
+dup a = (a, a)
+
+-- Not really an adder either, but a simple stateful example (D-flipflop)
+dff :: Bit -> Bit -> (Bit, Bit)
+dff d s = (s', q)
+ where
+ q = s
+ s' = d
+
+type ShifterState = (Bit, Bit, Bit, Bit)
+shifter :: Bit -> ShifterState -> (ShifterState, Bit)
+shifter i (a, b, c, d) =
+ (s', d)
+ where
+ s' = (i, a, b, c)
+
+{-# NOINLINE shifter_en #-}
+shifter_en :: Bit -> Bit-> ShifterState -> (ShifterState, Bit)
+shifter_en High i (a, b, c, d) =
+ (s', d)
+ where
+ s' = (i, a, b, c)
+
+shifter_en Low i s@(a, b, c, d) =
+ (s, d)
+
+-- Two multiplexed shifters
+type ShiftersState = (ShifterState, ShifterState)
+shifters :: Bit -> Bit -> ShiftersState -> (ShiftersState, Bit)
+shifters sel i (sa, sb) =
+ (s', out)
+ where
+ (sa', outa) = shifter_en sel i sa
+ (sb', outb) = shifter_en (hwnot sel) i sb
+ s' = (sa', sb')
+ out = if sel == High then outa else outb