let fold s f x = let rec loop y acc = let acc' = f y acc in try Set.fold loop (Map.find y s.inv) acc' with Not_found -> acc' in let (y, _) = find s x in loop y