[mercury-users] Nested Sub-Modules

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Sep 30 02:42:23 AEST 1998


On 29-Sep-1998, Dante Baldan <dba at info.fundp.ac.be> wrote:
> 
> I looked at this mailing-list archive, but I did not
> find any mail about nested sub-modules.
> I read the language reference manual, but it is not clear to
> me where nested submodules can be placed within
> parent module.
> 
> For example, I tried (Mercury 0.7.3) the following code:

The problem here is that nested modules are a new feature
that was not supported at all in Mercury 0.7.3.

The documentation on our WWW page is the documentation for the
"latest and greatest" version.  The documentation for each
particular version is included in both the source and binary
distributions of that version (in several formats, including
HTML and GNU info format).

> ========================================================
> :- module parent_mod.
> :- interface.
> :- import_module io.
> :- pred main(io__state::di,io__state::uo) is det.
> 
> :- implementation.
> 
> :- type list(T) ---> [] ; [T|list(T)].
> 
> :- module sub_mod.
> :- interface.
> :- implementation.
> :- import_module int.
> :- func sum(list(int))= int.
> :- mode sum(in) = out is det.
> sum([])=0.
> sum([X|L])=N :- sum(L)=N1, N is N1 + X.
> :- end_module sub_mod.
> 
> main --> {sum([1,2,3])=X}, io__write(X), 
>           io__write_string("\n").
> 
> :- end_module parent_mod.

That example is not quite legal: the call to `sum' in the body of main
is not allowed, because the contents of the child module `sub_mod' are
not visible from the main module unless it is explicitly imported. 
To make that example work, you need to add `:- import_module sub_mod'.

> Probably current Mercury implementation does not match
> completely the specification contained in the Language Reference
> Manual, but I think that (at least the skeleton of)
> some examples could be added to that
> manual in order to clarify the topic.

That is a good suggestion.  We'll see what we can do.

Cheers,
	Fergus.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the users mailing list