Four bit adder: Difference between revisions

→‎{{header|Haskell}}: replace adder function with one with 4 visible fulladders
m (J: clarify wording)
(→‎{{header|Haskell}}: replace adder function with one with 4 visible fulladders)
Line 724:
xor a b = uncurry nand. (nand a &&& nand b) $ nand a b</lang>
Adder circuits:
<lang haskell>halfAdder = (uncurry band &&& uncurry xor)
fullAdder (c, a, b) = (\(cy,s) -> first (bor cy) $ halfAdder (b, s)) $ halfAdder (c, a)
 
addadder4 as = foldr (\(f,a,b) (cy,xsbs) -> second(:xsbs) $ fullAdderf (cy,a,b)) (0,[]). zipzip3 (replicate 4 fullAdder) as</lang>
 
Example using add
Anonymous user