[m-users.] Mercury operators explained

Paul Bone paul at bone.id.au
Wed Feb 19 09:45:14 AEDT 2014


On Tue, Feb 18, 2014 at 10:11:35PM +0000, Piotr Trojanek wrote:
> Dear Mercury experts,
> 
> please excuse me for a naive question, but where can I find
> documentation of the Mercury operators?
>
> I was translating my code from SWI-Prolog and found that there is no
> "=\=" operator in Mercury. There are many other built-in operators
> listed in the Mercury Reference Manual, but they are not explained.

There is no =\= module in Mercury.  Arithmetic expressions are evaluated
immediately, they do not create terms so you do not need "is" "=:=" or "=\="
and so-on.  The normal unification and comparison operators should be used.

Operators are listed in the reference manual and explained in the library
documentation.  Operators such as "+" (like other predicates) can have
definitions in different modules, for example the int module defines + as
taking two "int"s and returning an "int", whereas the float module defines
+ as taking two "float"s and returning a "float".  If your program imports
both modules the compiler uses the types of variables in your program to
work out which definition of + to use.

Library reference:
http://www.mercurylang.org/information/doc-release/mercury_library/index.html

Some comparison operators are defined here:
http://www.mercurylang.org/information/doc-release/mercury_library/builtin.html#builtin

Goal operators such as conjunction, disjunction implication are defined in
the reference manual:
http://www.mercurylang.org/information/doc-release/mercury_ref/Goals.html#Goals

Some symbols, although I wouldn't call them operators others may disagree,
are used in declarations, for example the ---> used in type definitions are
described throughout the reference manual.

Also note that some symbols are used as both goal operators and symbols in
declarations.  For example implication <= is also used to describe typeclass
constraints.

I hope this helps.


-- 
Paul Bone



More information about the users mailing list