On Thu, 30 Nov 2006, Francois Colonna wrote:
> Hello
>
> have two mli files a.mli and b.mli, where b.mli is using the type "a"
> defined in a.mli :
> a.mli :
> type a = { x : float } ;;
>
> and b.mli :
> type b = { an_a : a} ;;
>
> how can I compile b.mli ?
You can't. At least not as writen.
The problem here is that you provide the compiler with no information
regarding where the type a came from, and so you will get an "Unbound type
constructor a" error when you try to compile it. You need to either open
the A module:
(** b.mli **)
open A;;
type b = { an_a : a} ;;
or fully specify the type name:
type b = { an_a : A.a } ;;
Once you do that, then you can do a:
ocamlc -c a.mli
ocamlc -c b.mli
to compile the interfaces (or just ocamlc -c a.mli b.mli -- note the
order is important).
Note that you will need to do this for b.ml as well. And for other
modules that make use of A and B. E.g.
(** c.ml **)
let a = { A.x = 1. };;
let b = { B.an_a = a };;
let _ = Printf.printf "a: %fn" b.B.an_a.A.x;;
> and where is this commented in the OCaml
> documentation ?
I don't know where it's covered specifically, but chapters 2 and 8
of the manual probably go over it.
William D. Neumann
---
"There's just so many extra children, we could just feed the
children to these tigers. We don't need them, we're not doing
anything with them.
Tigers are noble and sleek; children are loud and messy."
-- Neko Case
Life is unfair. Kill yourself or get over it.
-- Black Box Recorder
.