update (x:xs) i y
  | i < 0 = Nothing
  | i == 0 = return (y:xs)
  | otherwise = do
      new <- update xs (pred i) y
      return (x:new)
update (x:xs) i y
  | i < 0 = Nothing
  | i == 0 = return (y:xs)
  | otherwise = do
      new <- update xs (pred i) y
      return (x:new)
update (x:xs) i y
  | i < 0 = Nothing
  | i == 0 = return (y:xs)
  | otherwise = do
      new <- update xs (pred i) y
      return (x:new)