<br><br><div><span class="gmail_quote">On 3/4/06, <b class="gmail_sendername">Mark Brown</b> <<a href="mailto:mark@cs.mu.oz.au">mark@cs.mu.oz.au</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 04-Mar-2006, Jonathan Morgan <<a href="mailto:jonmmorgan@gmail.com">jonmmorgan@gmail.com</a>> wrote:<br>><br>>    I think that something like op/3 might be a useful feature.  I<br>>    certainly think that Haskell is far more powerful because of its use
<br>>    of user-defined operators in the standard library.<br>>    Haskell treats operators as functions, meaning that they can be<br>>    exported and used in typeclass definitions.  This means that you can<br>
>    have typeclasses like Ord, Eq and Num that provide operations like<br>>    (<), (>), (==), (+) etc., which means that user-defined code can<br>>    implement these type-classes, rather than leaving them a black box
<br>>    available only to the implementors of the compiler<br><br>Mercury has those operators, and you can define them however you like.<br>Indeed, that's what the int.m and float.m modules do.  You can easily<br>define a `num' typeclass in Mercury, but currently the standard library
<br>doesn't do it that way.</blockquote><div><br>I seem to remember reading something about user-defined equality not working well with Mercury - but I'm not sure why.  Also, Haskell's way provides type-class constraints, which you can then use in your function signatures.  Can anything like that be done with Mercury built-in operators?  (For example, I know C++ can have operators overloaded - but I know of no good way of making a function work over every class that has re-defined all the ordering operators, or whatever it might be).
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">The issue is whether you can make non-operator names into operators in<br>your program.  In Haskell, this would be equivalent to writing, say:
<br><br>        infix 3 member<br><br>instead of<br><br>        infix 3 `member`<br><br>which, as I pointed out a moment ago, Haskell will not accept.</blockquote><div><br>I have no particular objection to the back-ticks syntax - especially if it is extended to solve precedence and associativity problems.  What I was saying was that Haskell allows a particular subset of identifiers to be treated as operators, and I think that the op/3 syntax would benefit from this, as it would be much easier to identify what is an operator, and what is not.  I do not like the idea of any arbitrary word being an operator, as it would lessen the readability of the code, but I do think Haskell's idea of having (I think) up to five symbols together counted as an operator is sound.
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">>    However, Haskell also has limitations on what can qualify as an<br>>    operator, meaning that you cannot define arbitrary operators (I think
<br>>    they need to be all symbols, not just arbitrary words).<br><br>That's right.<br><br>> This enables<br>>    users to clearly distinguish between an infix operator and an infix<br>>    function (with back-ticks).  These infix functions can be given
<br>>    precedences and associativity, which makes them easier to use.<br><br>Correction: they can be given a precedence and associativity which differs<br>from the default, or from any previous values.</blockquote><div>
<br>The default will always be the same for infix functions currently though, won't it?   The real danger is in allowing people to change the precedence of built-in operators (eg. make (+) higher than (*)), as that would be confusing.  Should users be allowed to change the precedence of pre-defined operators at all (or issue any :- op command for an operator that is already defined)?
<br><br>I still think that user-defined operators lose most of their use if they cannot be exported, but I believe exporting them is going to cause more trouble.<br><br>Jon<br><br>Jon<br></div></div>