[mercury-users] boolean expressions from semidet predicates
Nicholas Nethercote
njn at csse.unimelb.edu.au
Tue May 16 04:27:52 AEST 2006
On Mon, 15 May 2006, Mark Brown wrote:
>> It has operators like '+', '++' and 'and',
>
> Yes, that means you can write `X and Y' instead of `and(X, Y)', etc. As
> I mentioned earlier, this has no impact on the semantics: both mean the
> same thing. Once Mercury has parsed the program, it no longer knows or
> cares whether infix notation was used.
>
>> but then there are functions int.+/2 and string.++/2 and bool.and/2.
>
> Yes. Where is the problem?
So in Mercury some of the names, such as 'and', are treated specially in
that you can write them infix. So this program works:
:- module a.
:- interface.
:- import_module io.
:- pred main(io :: di, io :: uo) is det.
:- implementation.
:- import_module string.
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. If you designed Mercury's syntax from scratch would you
still treat these names specially?
Oh... I think I see how it's useful at least for the non-alphabetical
operators. Since you can't create new operators in Mercury, the language
provides a bunch of built-in operators with no inherent meaning (literally
just pieces of concrete syntax), and then you can "populate" them with
whatever meaning you want. That's how things like int.</2 work.
Hmm, it still feels weird to me, and not at all clear from the Reference
Manual. Perhaps if I knew Prolog better this wouldn't seem weird (and the
"Mercury's syntax is almost identical to ISO-Prolog syntax" statements would
be more helpful).
Nick
--------------------------------------------------------------------------
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