Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] .ml and .mli
@ 2003-07-24  9:54 Emmanuel Filiot
  2003-07-24 10:18 ` Jacques Garrigue
  0 siblings, 1 reply; 2+ messages in thread
From: Emmanuel Filiot @ 2003-07-24  9:54 UTC (permalink / raw)
  To: caml-list

Hello all,

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

For example, I have some files such that :
 
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


I must copy "module type S = sig...." in both toto.ml and toto.mli.

Thanks

Emmanuel

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


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

* Re: [Caml-list] .ml and .mli
  2003-07-24  9:54 [Caml-list] .ml and .mli Emmanuel Filiot
@ 2003-07-24 10:18 ` Jacques Garrigue
  0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2003-07-24 10:18 UTC (permalink / raw)
  To: emmanuelfiliot; +Cc: caml-list

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


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

end of thread, other threads:[~2003-07-24 10:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-24  9:54 [Caml-list] .ml and .mli Emmanuel Filiot
2003-07-24 10:18 ` Jacques Garrigue

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox