Haskell solution for #112.