From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id 1F3EB7ED67 for ; Fri, 10 Aug 2012 23:30:27 +0200 (CEST) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of jeannin@cs.cornell.edu) identity=pra; client-ip=128.84.103.138; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="jeannin@cs.cornell.edu"; x-sender="jeannin@cs.cornell.edu"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of jeannin@cs.cornell.edu) identity=mailfrom; client-ip=128.84.103.138; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="jeannin@cs.cornell.edu"; x-sender="jeannin@cs.cornell.edu"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@exch-hub1.cs.cornell.edu) identity=helo; client-ip=128.84.103.138; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="jeannin@cs.cornell.edu"; x-sender="postmaster@exch-hub1.cs.cornell.edu"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlYCAMx4JVCAVGeKe2dsb2JhbABEuhkBARYmBSKCIj1APRYYAwIBAgFLDQgBAYgJC5Y+mCmJBJFzA4gZjkSESINQiV4 X-IronPort-AV: E=Sophos;i="4.77,748,1336341600"; d="scan'208";a="152859768" Received: from mail-hub-1.cs.cornell.edu (HELO exch-hub1.cs.cornell.edu) ([128.84.103.138]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-MD5; 10 Aug 2012 23:30:25 +0200 Received: from [128.84.98.107] (128.84.98.107) by mail.cs.cornell.edu (128.84.103.140) with Microsoft SMTP Server (TLS) id 8.3.245.1; Fri, 10 Aug 2012 17:30:23 -0400 Message-ID: <50257D72.2090607@cs.cornell.edu> Date: Fri, 10 Aug 2012 17:30:26 -0400 From: Jean-Baptiste Jeannin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 MIME-Version: 1.0 To: "caml-list@inria.fr" Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit Subject: [Caml-list] Exception Typetexp.Error(_, _) when using Toploop Hi all, I am getting a strange dynamic type error Typetexp.Error(_, _) when trying to compile files using Toploop. It is strange to me because the error appears or not depending on which directory I compile from (while adapting all the paths, of course). I narrowed it down to two small files but am now stuck. My understanding (from comments in http://caml.inria.fr/svn/ocaml/branches/gadts/typing/typetexp.ml) is that it is a type error that is happening when trying to dynamically interpret (using Toploop) a dynamically generated piece of code, located in a string. Here is how to reproduce the error. In a directory, create a subdirectory subdir, and in this subdirectory create a file tree.ml containing the code: type tree = Leaf | Node of tree * tree;; in the main directory, create a file prog.ml containing the code: let s = "let t = Tree.Leaf;;" in let lexed = Lexing.from_string s in let parsed = (!Toploop.parse_toplevel_phrase) lexed in Toploop.execute_phrase true Format.err_formatter parsed;; If trying to compile them inside subdir, it works fine: $ cd subdir $ ocamlc -o prog.exe -I .. toplevellib.cma tree.ml ../prog.ml $ ./prog.exe val t : Tree.tree = Tree.Leaf However, if trying to compile them from the top directory (which is what I would like to do), it does not work and raises a Typetexp.Error(_, _) exception at runtime: $ cd .. $ ocamlc -o prog.exe -I subdir toplevellib.cma subdir/tree.ml prog.ml $ ./prog.exe Fatal error: exception Typetexp.Error(_, _) If putting both files in the same directory and compiling them together it works too (but I would prefer not to do that): $ ocamlc -o prog.exe -I subdir toplevellib.cma tree.ml prog.ml $ ./prog.exe val t : Tree.tree = Tree.Leaf I think what happens is that the Tree.Leaf is not recognized because the module Tree is not in the directory from which we are compiling. Any idea how to fix this, while keeping the directory structure and compiling from the top directory, or any better understanding of what is happening? Thanks, Jean-Baptiste Jeannin Please note: the commands above were executed with OCaml 3.12.0. If you are using 4.00.0 my understanding (although not tested) is that you should replace "toplevellib.cma" by "+compiler-libs ocamlcommon.cma ocamlbytecomp.cma ocamltoplevel.cma" everywhere