method ref f r = let self, v = f self !r in if !r == v then self, r else self, ref v

- method list f xs = List.fold_right (fun x (self, xs) ->

- let self, x = f self x in

- self, x::xs) xs (self, [])

+ let self, ys = List.fold_right (fun x (self, xs) ->

+ let self, x = f self x in

+ self, x::xs) xs (self, [])

+ if List.for_all2 (==) xs ys then self, xs else self, ys

(* Oh it's really a map. not bind *)

method option f = function

- | Some v -> let self, v' = f self v in self, Some v'

+ | (Some v as o) -> let self, v' = f self v in if v == v' then self, o else self, Some v'