Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] .ml and .mli
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] .ml and .mli
From: Emmanuel Filiot <emmanuelfiliot@wanadoo.fr>

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

There is no 100% equivalent solution.

> toto.mli
> 
> 	module type S = sig type t end	
> 
> 	module A : S with type t = int
> 
> toto.ml
> 
> 	module type S = sig type t end
> 
> 	module A = struct type t = int let id x = x end	
> 
> tutu.ml
> 
>         open Toto
> 
> 	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