from array update algorithm to nice Haskell code