[mercury-users] more Mercury homework: "Mercuryfy" some simple Prolog

Peter Ross pro at missioncriticalit.com
Sun Sep 26 17:25:08 AEST 2010


On Sat, Sep 25, 2010 at 1:01 AM, Jean-Marc Vanel
<jeanmarc.vanel at gmail.com> wrote:
> 2010/9/24 Peter Ross <pro at missioncriticalit.com>
>>
>> > But, then, what to put in the implementation, which would the equivalent
>> > of
>> > an empty class in Java ?
>> >
>> The equivalent to the empty class is.
>>
>> :- type person ---> person.
>
> If I undertand well, this would be a class, but with no possibility to
> create instances.

The following creates an instance

  X = person

however I think we're trying to stretch the analogy a bit too far.


> Reading the mercury_trans_guide :
> http://www.mercury.csse.unimelb.edu.au/information/doc-release/mercury_trans_guide/Syntax.html#Syntax
> it begins with the sentence :
> Prolog and Mercury have very similar syntax. Although there are a few
> differences, by and large if a program is accepted by a Prolog system, it
> will be accepted by Mercury.
> It seems to me that this is over-optimistic.
> A simple and typical Prolog program like :
> brother( jacques, simone ).
> parent( simone, jean_marc ).
> uncle(Uncle,Person) :-
>         brother(Uncle,Parent), parent(Parent,Person).
> requires quite a large quantity of boilerplate code.
> Here the translation I did:
> :- module artOfProlog_program_2_1_short .
> :- interface.
> :- import_module io.
> :- pred main(io::di, io::uo) is cc_multi. % det.
> :- implementation.
> %%%% declarations %%%%
> :- import_module string.
> :- type person.
> :- func create( string ) = person .
> :- pred uncle( person/*Uncle*/::out, person::in ) is nondet .
> :- pred brother( person, person) is nondet .
> :- mode brother( in, out ) is nondet .
> :- mode brother( out, in ) is nondet .
> :- pred parent(person, person).
> :- mode parent(in, out) is semidet. % not everyone is a parent
> % :- mode parent(out, in) is det.  % everyone has a parent
> :- mode parent(out, in) is semidet.
> %%%% implementation %%%%
> :- type person == string .
> create( S ) = S .
> %%%% facts %%%%
> brother( create("jacques"), create("simone")).
> parent( create("simone"), create("jean_marc") ).
> %%%% rules %%%%
> uncle(Uncle,Person) :-
>         brother(Uncle,Parent), parent(Parent,Person).
> main(!IO) :-
>         uncle(Uncle, create("jean_marc") )
> -> (
>         io.write( Uncle, !IO),
>         io.write_string( " is an uncle.\n", !IO)
> ) ;
>         io.write_string( "Fail\n", !IO)
> .
> I recognize that most of this necessary for a language for developing large
> and modular programs.
> But this really points to the lack of documentation. The tutorial is
> skeletal, and the manual is laconic.
> Happily the community is here and answers !
> 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 ?

Yes Mercury does require a large amount of declarations, because it
was designed for programming in the large.  However I don't think you
will find the step to doing non-trivial stuff to be as big as you
think.


> Compare with a language like Scala, which is 6 years younger than Mercury.
> Scala has many tutorials and books.
> I know that Scala has no logic programming features, so Mercury still is
> promising.

It is an issue with Mercury, the lack of beginner level documentation.
 Unfortunately no-one has volunteered to write anything else.
Hopefully one day.

Pete

--------------------------------------------------------------------------
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