Skip to content

Instantly share code, notes, and snippets.

@hudon
Created October 1, 2016 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hudon/424d483a91b54f69f9e0c6f74735e945 to your computer and use it in GitHub Desktop.
Save hudon/424d483a91b54f69f9e0c6f74735e945 to your computer and use it in GitHub Desktop.
add two lists of arbitrary bytes
byteSum :: [Word8] -> [Word8] -> [Word8]
byteSum = byteSum' 0
where
byteSum' 0 [] [] = []
byteSum' 1 [] [] = [1]
byteSum' carry (x:xs) (y:ys) =
let v = x + y + carry
in v : byteSum' (if v < x || v < y then 1 else 0) xs ys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment