Skip to content

Latest commit

 

History

History
10 lines (8 loc) · 426 Bytes

12-long-addition.md

File metadata and controls

10 lines (8 loc) · 426 Bytes

Exercise 12

Below is terribly wrong code for long addition, where numbers are represented as lists of decimal digits:

addLnat [x] [y] = rem  (x + y) 10 : (quot (x + y) 10) : []          
addLnat (x:xs) (y:ys) =  (rem  (x + y) 10) : w + head (addLnat xs ys)
                            where w = quot (x + y) 10

Fix type errors in the code above. Find a counterexample for which the code gives wrong answer.