[m-dev.] Re: user-defined operators

Ralph Becket rwab1 at cam.sri.com
Thu Jul 8 21:34:24 AEST 1999


> However, it is non-trivial to implement, if you want to do it properly.
> The problem is the way in which it interacts with the module system.
> Supporting user-defined operators within a single module would not be
> too hard, but really you'd like to be able to declare operators in
> the interface section of a module and have them exported to other
> modules.  Unfortunately allowing that makes things much trickier...

I have a suggestion.  Why not make pre/post/infix-ness a module-local
property?  That is, apart from the standard operators, if someone
wants to use `foo/2' as an operator in a particular module, they would
have to do the following:

:- import_module name_of_module_exporting_foo.

:- op(foo, xfy, 900).

...

:- implementation.

bar(X, Y, Z) :- X foo Y foo Z.

Now op/3 declarations affect only the parsing of the file/module to
which they belong.  I would imagine this would greatly simplify the
parsing problem wrt modules and would prevent unwanted operator-space
pollution by over-enthusiastic beginners.  In the absence of the op/3
declaration, standard syntax would be necessary.

Ralph

-- 
Ralph Becket  |  rwab1 at cam.sri.com  |  http://www.cam.sri.com/people/becket.html
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list