[m-dev.] 0.13 release: op/3 syntax

Jonathan Morgan jonmmorgan at gmail.com
Sat Mar 4 18:35:26 AEDT 2006


I think that something like op/3 might be a useful feature.  I certainly
think that Haskell is far more powerful because of its use of user-defined
operators in the standard library.

Haskell treats operators as functions, meaning that they can be exported and
used in typeclass definitions.  This means that you can have typeclasses
like Ord, Eq and Num that provide operations like (<), (>), (==), (+) etc.,
which means that user-defined code can implement these type-classes, rather
than leaving them a black box available only to the implementors of the
compiler (it also could simplify the parser, as, rather than having to
change the parser to support that new library function, you could just
define a new op).

User-defined operators are also used in high level GUIs like Fudgets and
Fran, in order to make code that is concise but expressive, as well as in
function composition (the (.) operator) and in Monads (including I/O).  This
is not currently available to Mercury developers.  I can see that
user-defined operators might be useful in specifying streams, in order to
create a notation that is both compact and expressive.

However, Haskell also has limitations on what can qualify as an operator,
meaning that you cannot define arbitrary operators (I think they need to be
all symbols, not just arbitrary words).  This enables users to clearly
distinguish between an infix operator and an infix function (with
back-ticks).  These infix functions can be given precedences and
associativity, which makes them easier to use.

Having an operator as a function makes it just as exportable as any other
function.  I think that user-defined operators lose much of their
applicability if they can't be exported, as it means that you would need to
define them in every module that uses them, giving you a classic double
maintenance problem.  It would also probably mean that they were never used
in libraries, which would limit their usefulness.

In short: I think that the user-defined operators ought to be able to be
exportable from modules, and also part of the typeclass system.  I think
that they should be useful, but, for the reasons given in this thread, I do
not think that they are ready for mercury-0.13.

Jon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/developers/attachments/20060304/575bc8e3/attachment.html>


More information about the developers mailing list