From a196bb880226453e009a7102126579376ba8add8 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Wed, 22 Feb 2012 18:25:22 +0100 Subject: [PATCH] better detection of Lwt.t values Ignore-this: c1fb44905029d45646301f66bb3ca078 darcs-hash:20120222172522-c41ad-e4fb0b9b6d0245d4aa958c69bcce3969c822795a --- src/lib/uTop_main.ml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lib/uTop_main.ml b/src/lib/uTop_main.ml index 2ce1518..aac244a 100644 --- a/src/lib/uTop_main.ml +++ b/src/lib/uTop_main.ml @@ -216,6 +216,15 @@ let is_eval = function | { Parsetree.pstr_desc = Parsetree.Pstr_eval _ } -> true | _ -> false +let rec is_lwt_t typ = + match typ.Types.desc with + | Types.Tlink typ -> + is_lwt_t typ + | Types.Tconstr (Path.Pdot (Path.Pident id, "t", -1), _, _) -> + Ident.persistent id && Ident.name id = "Lwt" + | _ -> + false + let insert_lwt_main_run phrase = match phrase with | Parsetree.Ptop_def pstr -> @@ -237,13 +246,8 @@ let insert_lwt_main_run phrase = (fun pstr_item tstr_item -> match pstr_item, tstr_item with | { Parsetree.pstr_desc = Parsetree.Pstr_eval e; Parsetree.pstr_loc = loc }, - Typedtree.Tstr_eval { - Typedtree.exp_type = { - Types.desc = - Types.Tconstr (Path.Pdot (Path.Pident id, "t", -1), _, _) - } - } -> - if Ident.persistent id && Ident.name id = "Lwt" then { + Typedtree.Tstr_eval { Typedtree.exp_type = typ } when is_lwt_t typ -> + { Parsetree.pstr_desc = Parsetree.Pstr_eval { Parsetree.pexp_desc = @@ -253,8 +257,7 @@ let insert_lwt_main_run phrase = Parsetree.pexp_loc = loc; }; Parsetree.pstr_loc = loc; - } else - pstr_item + } | _ -> pstr_item) pstr tstr)