Complete p008 in Haskell