let apply map sl a =
let jl = ref [] in
let lookup y =
let rec loop = function
| [] -> y
| ((x, b), j) :: sl' ->
if eq x y then (jl := j :: !jl; b) else loop sl'
in
loop sl
in
let b = map lookup a in
(b, !jl)