<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/07/b69c564dc7b1ba8a6e43eddb26d003df"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2003-07-24T10:18:21"
  subject="Re: [Caml-list] .ml and .mli"
  prev="2003/07/3b506b7bfe65dffafe21cc955de37f7a"
  next="2003/07/1ea3ba8ac1995e031abab081bf877be1"
  prev-in-thread="2003/07/3b506b7bfe65dffafe21cc955de37f7a"
  prev-thread="2003/07/d9552a523f855e9aec83425fe88835cb"
  next-thread="2003/07/1ea3ba8ac1995e031abab081bf877be1"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] .ml and .mli">
<msg 
  url="2003/07/3b506b7bfe65dffafe21cc955de37f7a"
  from="Emmanuel Filiot &lt;emmanuelfiliot@w...&gt;"
  author="Emmanuel Filiot"
  date="2003-07-24T10:00:46"
  subject="[Caml-list] .ml and .mli">
<msg 
  url="2003/07/b69c564dc7b1ba8a6e43eddb26d003df"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2003-07-24T10:18:21"
  subject="Re: [Caml-list] .ml and .mli">
</msg>
</msg>
</thread>

<contents>
From: Emmanuel Filiot &lt;emmanuelfiliot@wanadoo.fr&gt;

&gt; I have noticed that we must copy code between .ml and .mli, and I wonder
&gt; if there exists a solution for this problem.

There is no 100% equivalent solution.

&gt; toto.mli
&gt; 
&gt; 	module type S = sig type t end	
&gt; 
&gt; 	module A : S with type t = int
&gt; 
&gt; toto.ml
&gt; 
&gt; 	module type S = sig type t end
&gt; 
&gt; 	module A = struct type t = int let id x = x end	
&gt; 
&gt; tutu.ml
&gt; 
&gt;         open Toto
&gt; 
&gt; 	module B : S = struct .... end

A reasonably clean way to do that would be:

toto_s.mli
        module type S = sig type t end

toto.mli
        open Toto_s
        module A : S with type t = int

toto.ml
        open Toto_s
        module A = struct type t = int let id x = x end

tutu.ml
        open Toto_s
        module B : S = struct .... end

Note that you don't need a toto_s.ml, as it contains only types.
This is a nice trick when you have lots of type definitions.

By the way, one could do a bit closer to the original if
[include Toto_s] was allowed in toto.mli. Then, we could keep
[open Toto] in tutu.ml.
Unfortunately, a .mli does not define a signature, so this is not
allowed :-(

        Jacques

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

