[Haskell-beginners] Shorten this code