caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Hongbo Zhang <bobzhang1988@gmail.com>
To: Jean-Baptiste Jeannin <jeannin@cs.cornell.edu>
Cc: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: [Caml-list] Re: Exception Typetexp.Error(_, _) when using Toploop
Date: Fri, 10 Aug 2012 20:14:43 -0400	[thread overview]
Message-ID: <5025A3F3.4000109@gmail.com> (raw)
In-Reply-To: <50257D72.2090607@cs.cornell.edu>

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
>


  reply	other threads:[~2012-08-11  0:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-10 21:30 [Caml-list] " Jean-Baptiste Jeannin
2012-08-11  0:14 ` Hongbo Zhang [this message]
2012-08-11 20:03   ` [Caml-list] " Jean-Baptiste Jeannin
2012-08-11  8:34 ` [Caml-list] " Jérémie Dimino
2012-08-11 20:15   ` Jean-Baptiste Jeannin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5025A3F3.4000109@gmail.com \
    --to=bobzhang1988@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=jeannin@cs.cornell.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).