haskell version of assignment 4 -- needs cleanup, but works