We can either chose an function version:
     
let ftv_type t = let visited = marker() in let rec visit ftv t = let t = repr t in if t.mark = visited then ftv else begin t.mark <- visited; match desc t with | Tvar _ -> t::ftv | Tcon (g, l) -> List.fold_left visit ftv l end in visit [] t;;
or an imperative version:
     
let ftv_type t = let ftv = ref [] in let visited = marker() in let rec visit t = let t = repr t in if t.mark = visited then () else begin t.mark <- visited; match desc t with | Tvar _ -> ftv := t::!ftv | Tcon (g, l) -> List.iter visit l end in visit t; !ftv;;