[mercury-users] boolean expressions from semidet predicates
Peter Schachte
schachte at csse.unimelb.edu.au
Tue May 16 12:47:28 AEST 2006
On Tue, May 16, 2006 at 04:27:52AM +1000, Nicholas Nethercote wrote:
> main(!IO) :-
> io.write_string("hello\n" and "goodbye\n", !IO).
>
> :- func and(string, string) = string.
> and(A, B) = A ++ B.
>
> but if you change the name of and/2 to foo/2 it doesn't work.
>
> So in Mercury some names are syntactically special (ie. they can be used
> infix) but you have to supply the meaning. It's not a problem, but I find
> it really weird.
I've always thought C was kind of weird in using % for modulo and ^
for xor. The latter symbol would be much more natural for
exponentiation, but that's not a built-in operation, so it can't be an
operator. And using 'mod' for the former operation is ruled out
because it's alphabetic, and alphabetic functions can't be built-ins,
and can't be operators. Of course, they *could*, but C had decided
that all operators should be non-alphabetic and should not be
user-definable, and no alphabetic symbols should be operators or
builtins (well, except for sizeof). Persisting with this unnatural
dichotomy in a language designed for abstract datatypes, as Java does,
makes some programs pretty ugly. Allowing overloading, as C++ and
Mercury do, makes for more natural looking programs. But deciding
that certain types are build-in and have access to operator syntax,
and no other types do, seems pretty ugly to me. The nicest approach,
which Mercury moves a long way toward, is to have no builtin types,
and all operations implemented as libraries that any user could have
written. So if I want to support fixed point numbers, or rational
numbers, or strings with constant-time concatenation, I can do so
without having to use a syntax incompatible with the standard types.
The main difficulty in fully providing this flexibility is handling
manifest constants.
Where Mercury is less pleasant is that it decides once and for all (or
until the next Mercury release) which symbols can be used as
operators, with what fixity, associativity, and precedence, and no
others can. I'd really like to be able to write programs the way I
write papers with latex: choose the nicest looking symbols and nicest
syntax to express my ideas.
--
Peter Schachte Truth is the most valuable thing we have -- so
schachte at cs.mu.OZ.AU let us economize it.
www.cs.mu.oz.au/~schachte/ -- Mark Twain
Phone: +61 3 8344 1338
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list