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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 0FE6F7ED67 for ; Sat, 11 Aug 2012 02:14:57 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of bobzhang1988@gmail.com) identity=pra; client-ip=209.85.160.54; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="bobzhang1988@gmail.com"; x-sender="bobzhang1988@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of bobzhang1988@gmail.com designates 209.85.160.54 as permitted sender) identity=mailfrom; client-ip=209.85.160.54; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="bobzhang1988@gmail.com"; x-sender="bobzhang1988@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-pb0-f54.google.com) identity=helo; client-ip=209.85.160.54; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="bobzhang1988@gmail.com"; x-sender="postmaster@mail-pb0-f54.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtsCAMx4JVDRVaA2jWdsb2JhbABEDrlhCCIBAQEBBwsmBiOCIAEBAQQBAQEPAiQIARscAQEDDAYFCw0JFg8JAwIBAgEREQEFARwGDQEHAQEeh1sBAwsBC5kfCQOMI4JyhQYKGScNV4hxAQUMkWcDlUmBFIgYhQY+g0VV X-IronPort-AV: E=Sophos;i="4.77,749,1336341600"; d="scan'208";a="169624259" Received: from mail-pb0-f54.google.com ([209.85.160.54]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 11 Aug 2012 02:14:56 +0200 Received: by pbbrp2 with SMTP id rp2so4260205pbb.27 for ; Fri, 10 Aug 2012 17:14:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:newsgroups:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=lymu2hrRUX5fDF/XwnnB3DSnq1f2nSC3MuEyub3rj18=; b=x74lv9yUHnk06ge0dlXCSjVu5nW3R0bituP6uAHJtwfUYOS8Cr8pCPwCgbw0HdSegK QZXer4624p3z7uR9UzXihnfC3l+TUQ+UmFupg3J4C3sJe4iBo7CR+ihvD3Jr8dJT9dGr 8azpBsxwvy72iOPtcN+KYa/Sr6PIubOI8MPg4rMO+BR1GHbe0WYerm4dxphAKLyPU1Fs st/8IF+mhC8Cvc/aO7Ozry15nhrjZuhG/vzWIEZuvFwVJ+gjTMUqDuXnADdCesrF3666 3GvqcwMjZGWwUZSweAlg607xuZycQjDVmLUkFM0oFmDJ0v0henO6EfvMKCSemBdmTZ6B 7JRw== Received: by 10.68.219.226 with SMTP id pr2mr1856592pbc.1.1344644094457; Fri, 10 Aug 2012 17:14:54 -0700 (PDT) Received: from Hongbos-MacBook-Air.local ([113.88.226.180]) by mx.google.com with ESMTPS id vm5sm233649pbc.22.2012.08.10.17.14.49 (version=SSLv3 cipher=OTHER); Fri, 10 Aug 2012 17:14:52 -0700 (PDT) Message-ID: <5025A3F3.4000109@gmail.com> Date: Fri, 10 Aug 2012 20:14:43 -0400 From: Hongbo Zhang User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 Newsgroups: gmane.comp.lang.caml.inria To: Jean-Baptiste Jeannin CC: "caml-list@inria.fr" References: <50257D72.2090607@cs.cornell.edu> In-Reply-To: <50257D72.2090607@cs.cornell.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Caml-list] Re: Exception Typetexp.Error(_, _) when using Toploop On 8/10/12 5:30 PM, Jean-Baptiste Jeannin wrote: > Hi all, > Greetings, > 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(_, _) > Are you sure tree.cmo is linked in? what's the output of ocamlobjinfo prog.exe? > 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 >