caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Exception Typetexp.Error(_, _) when using Toploop
@ 2012-08-10 21:30 Jean-Baptiste Jeannin
  2012-08-11  0:14 ` [Caml-list] " Hongbo Zhang
  2012-08-11  8:34 ` [Caml-list] " Jérémie Dimino
  0 siblings, 2 replies; 5+ messages in thread
From: Jean-Baptiste Jeannin @ 2012-08-10 21:30 UTC (permalink / raw)
  To: caml-list

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-08-11 20:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-10 21:30 [Caml-list] Exception Typetexp.Error(_, _) when using Toploop Jean-Baptiste Jeannin
2012-08-11  0:14 ` [Caml-list] " Hongbo Zhang
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

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).