Solution to UPenn's Haskell course homework