Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-10-20 (20:04)
From: Alessandro Baretta <alex@b...>
Subject: [Caml-list] Re:
I must advise you to download the O'Reilly caml-book, and
read through it. The answers to all your questions are in there.


climb wrote:
>  i am quite confused about the orgnization of source files.
> i have programmed with java . java has a simple rule to orgnize files: one file contains one class(public) or interface, and name of the file and the class  must be identical.
> As to Ocaml.
> Does the file name of *.ml or mli has some similar relation ship with the content ?
>   for example , in the on-line manul
>   it says :
>   if complie like this
>   ocaml -c aux.mli
>   ocaml -c
>   behaves exactly as if 
>   module Aux: sig (* contents of aux.mli*) end = struct (*contents of*) end;;
>   in the toplevel
>   that seems to imply the exsiting fo some relationship , but i still has these questions:
> 1) can many modules be write in just one file ? 
>    maybe not , then how does classes?

Yes. Modules can contain modules. Every compilation unit
automatically defines a module. An ".mli" defines the
signature of the module defined ecapsulating the
corresponding ".ml".

> 2) Is the multi sigs with one struct  or multi structs  with one sig  compiled at a prper dependency can get the same result that like as in the toplevel?   should i write anther file to tell them how to assigning?

I don't understand what you mean.

> 3) take and set.mli for example which defined one functor: Make and two sigs : S and OrderedType.  But when we use , we use this command    Set.Make(..).       "Set" here seem can only get from the name of the file. So it seems the file name determined the library name .  Then how about the noraml module (not functor) case that if i define a module A with a funtion a(), in file and b.mli, how can i refer to a() in module A.  A.a() or B.A.a() or B.a()? 

As I already pointed out, the compiler encapsulates every
".ml" in its own module declaration, where the name of the
module is equal to the name of file, with the first letter
capitalized. Therefore, if you can write

> (* File *)
> module Abc = struct
>   let function_of_abc () = ...
> end

> (* File *)
> let _ = X.Abc.function_of_abc ()


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: