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

Mark Brown mark at cs.mu.OZ.AU
Sat Mar 4 19:45:35 AEDT 2006


On 04-Mar-2006, Jonathan Morgan <jonmmorgan at gmail.com> wrote:
> 
>    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

Mercury has those operators, and you can define them however you like.
Indeed, that's what the int.m and float.m modules do.  You can easily
define a `num' typeclass in Mercury, but currently the standard library
doesn't do it that way.

The issue is whether you can make non-operator names into operators in
your program.  In Haskell, this would be equivalent to writing, say:

	infix 3 member

instead of

	infix 3 `member`

which, as I pointed out a moment ago, Haskell will not accept.

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

That's right.

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

Correction: they can be given a precedence and associativity which differs
from the default, or from any previous values.

Cheers,
Mark.

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