[mercury-users] more Mercury homework: "Mercuryfy" some simple Prolog
Tomas By
tomas at basun.net
Mon Sep 27 01:47:35 AEST 2010
On Fri, September 24, 2010 17:01, Jean-Marc Vanel wrote:
> 2010/9/24 Peter Ross <pro at missioncriticalit.com>
> A simple and typical Prolog program [...]
> requires quite a large quantity of boilerplate code.
The Prolog code represents people using atoms, and you can do that
in Mercury also. Your "create" function is pointless, and some of
your mode declarations are not used (and you have more than one
parent and can have any number of children).
| :- module vanel.
| :- interface.
| :- import_module io.
| :- pred main(io::di, io::uo) is cc_multi.
| :- implementation.
|
| :- type person ---> jacques ; simone ; jean_marc.
|
| :- pred uncle( person/*Uncle*/::out, person::in ) is nondet.
| :- pred brother( person::out, person::in ) is nondet.
| :- pred parent( person::out, person::in ) is nondet.
|
| brother( jacques, simone ).
| parent( simone, jean_marc ).
|
| uncle(Uncle,Person) :-
| brother(Uncle,Parent), parent(Parent,Person).
|
| main(!IO) :-
| ( uncle(Uncle,jean_marc) ->
| io.write( Uncle, !IO),
| io.write_string( " is an uncle.\n", !IO)
| ; io.write_string( "Fail\n", !IO) ).
|
| :- end_module vanel.
The actual functionality code here is identical to the Prolog version.
> But I really wonder if it is possible to learn the language without living
> in Melbourne or Brussels, and meeting the Gurus often.
> These are only simple things I tried until now. What time will it take me
> to do non trivial stuff ?
Somebody who knows Prolog does not really need to learn Mercury. You can
basically just add declarations and a main procedure and have something
that compiles. There are certain things that need to be changed (eg
assert/retract, repeat-fail loops), and you will quickly start doing
some things differently (you'd probably need to have a psychological
disorder to be able to continue writing _every single loop_ as a recursive
procedure, for example).
Having said that, and having had a quick look at you CV on your website,
I think you may be better off staying with Prolog. There are books you
can read, there are much more mature tools, there are plenty of libraries.
The lack of Unicode support in Mercury, in particular, may be an issue.
/Tomas
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list