Nested Sub-Modules

Dante Baldan dba at info.fundp.ac.be
Wed Sep 30 01:53:25 AEST 1998


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:

========================================================
:- 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.
=========================================================

but the Mercury compiler does not like it because
it seems to consider the DCG definition of main/2
as part of sub_mod rather than parent_mod.
If I exchange the definition of module with the definition of
main/2 then the Mercury compiler is happy with that (!).

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.

Dante








Dante Baldan                    Institut d'Informatique FUNDP
21, rue Grandgagnage            5000 Namur
Phone: +32 81 72 49 99          Fax: +32 81 72 49 67
Email: dba at info.fundp.ac.be 		




More information about the users mailing list