Version française
Home     About     Download     Resources     Contact us    
Browse thread
Nesting Modules
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Tom Hawkins <tom@c...>
Subject: Re: [Caml-list] Nesting Modules
William D. Neumann wrote:
> On Tue, 1 Nov 2005, Tom Hawkins wrote:
> 
>> Is it possible to nest modules defined in separate files?
>>
>> For example, assume I have...
>>
>>  top.ml
>>  top.mli
>>  bottom.ml
>>  bottom.mli
>>
>> Can I instruct the compiler to nest Bottom somewhere in Top, to obtain 
>> clean, hierarchical names (eg: Top.Bottom.some_function)?  Of course I 
>> can inline bottom.ml in top.ml, but then the file become rather large.
> 
> 
> Sort of.  You can use include to minimize the file bloat.  A stupid 
> example follows:

Thanks William, this helps.  One question below...

> 
> ------
> (************************************************************************ *
> * bottom.ml
> *
> ************************************************************************)
> 
> let mname = "Bottom"
> 
> let id x = x -----
> 
> -----
> (************************************************************************
> *
> *  bottom.mli
> *
> ************************************************************************)
> 
> val mname : string
> val id : 'a -> 'a
> -----
> 
> -----
> (************************************************************************
> *
> *  top.ml
> *
> ************************************************************************)
> 
> let mname = "Top"
> 
> let id x = x
> 
> let double x = x + x
> 
> module Bottom =
>   struct
>     include Bottom
>   end
> -----
> 
> -----
> (************************************************************************
> *
> *  top.mli
> *
> ************************************************************************)
> 
> val mname : string
> 
> val id : 'a -> 'a
> 
> val double : int -> int
> 
> module Bottom : sig
>   val mname : string
>   val id : 'a -> 'a
> end

Why repeat Bottom's specification?  Why can't we do...

module Bottom : sig
   include Bottom
end

It appears to be valid syntax, but I get a "Unbound module type Bottom" 
when I try it.

-Tom