4-Bit Ripple Carry Adder in Haskell I recently started learning Haskell and had to program a 4 Bit Ripple Carry Adder that worked with tuples of the form 

type Nibble = (Bool, Bool, Bool, Bool) 


Beforehand I wrote the functions

-- XOR operator
xor :: Bool -&gt; Bool -&gt; Bool
xor a b = (not (a &amp;&amp; b) ) &amp;&amp; (a || b)

-- Fulladder for 1-Bit binary numbers  
-- Returns Tuple in the Form (add Carry, Sum) 
fulladder :: Bool -&gt; Bool -&gt; Bool -&gt; (Bool, Bool)
fulladder a b ci = ( (a &amp;&amp; b) || ( (xor a b) &amp;&amp; ci ), xor ci (xor a b) )

-- Second Element of (Bool, Bool)
saccess :: (Bool, Bool) -&gt; Bool
saccess (f, a) = a

-- First Element of (Bool, Bool)
faccess :: (Bool, Bool) -&gt; Bool
faccess (a, f) = a

-- 4-Bit Adder that does Nibble + Nibble = Nibble
rippleCarryAdder :: Nibble -&gt; Nibble -&gt; Nibble
rippleCarryAdder (a0, a1, a2, a3) (b0, b1, b2, b3) = (saccess (fulladder a0 b0 (faccess (fulladder a1 b1 (faccess (fulladder a2 b2 (faccess (fulladder a3 b3 False))))))), saccess (fulladder a1 b1 (faccess (fulladder a2 b2 (faccess (fulladder a3 b3 False))))), saccess (fulladder a2 b2 (faccess (fulladder a3 b3 False ))), saccess (fulladder a3 b3 False) )


I have the constraint that I can't change the types in the definitions of the functions fulladder and rippleCarryAdder. So one has to work with Nibble.
I would like to know if there is a more elegant way to work with the tuples returned by fulladder without defining a lot of other functions.
rippleCarryAdder is very hard to read. We can make it a lot easier to read if we use local bindings with let … in …:

rippleCarryAdder :: Nibble -&gt; Nibble -&gt; Nibble
rippleCarryAdder (a0, a1, a2, a3) (b0, b1, b2, b3) =
   let (r3, c3) = fulladder a3 b3 False
       (r2, c2) = fulladder a2 b2 c3
       (r1, c1) = fulladder a1 b1 c2
       (r0, _ ) = fulladder a0 b0 c1
   in (r0, r1, r2, r3)


We also don't have to recalculate fulladder a3 b3 False four times.



The functions faccess and saccess already exist and are called fst and snd.