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

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Sep 8 05:00:09 AEST 1999


On 08-Jul-1999, Ralph Becket <rwab1 at cam.sri.com> wrote:
> > 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.

Well, I considered that approach, but to me it just didn't seem like a
satisfactory solution to the problem.
The builtin operators would still be special and user-defined operators
added using this mechanism would feel second-class.
As a library user I would find it annoying having to copy the
operator declarations from the library's documentation into
my source code -- that feels like the sort of thing that a computer
should do.  As a library implementor I would find it frustrating that
I could not add user-defined operators without forcing such inconveniences
on the users of my library.  So I just don't think this would really make
anyone very happy.

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