Convert the C portion of the program to Haskell