implementation of amit's xform problem in haskell