[mercury-users] Mercury needs a Tutorial

Tyson Dowd trd at cs.mu.OZ.AU
Fri Feb 12 16:50:59 AEDT 1999


On 12-Feb-1999, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> On Thu, Feb 11, 1999 at 09:57:11AM +0000, Ralph Becket wrote:
> 
> >  I've started out with "Hello, World!"
> > as is the tradition.
> 
> I don't think this is a good way to start.  I think it's better to
> leave out as much as possible at the start, and work up to "Hello,
> World!".  This may be heretical among Mercurians, but I think you
> should avoid all declarations for the first examples, and add them as
> you go along.  Make use of type, mode, and determinism inference!
> 
> You might proceed like:  start with arithmetic, just because it'll look
> familiar and comfortable; then discuss database-y predicates; then
> define a predicate in terms of other predicates; then cover recursion;
> then hit types and type declarations; then pred declarations; then you
> might as well cover func declarations and functions; then cover
> instantiation and modes; then determinism; then uniqueness and mostly
> uniqueness; then a quick mention of main/2.  That's probably enough to
> get people going with Mercury.  It's quite a lot, isn't it?

I think hello world can be given at first, but you don't have
to explain what it all means.  Start with hello world as an
exercise to get compilation going and to get people to create a program
that gives output.

Then you can go back to arithmetic by making a new predicate
that is called to get a value which will be printed.

	e.g.   main --> { do_some_arith(X) }, write(X).

	do_some_arith(X) :-
		X is 2 + 2.

This way you can keep compiling the program with each set and seeing
that the output is right.  The learning part of the program
(do_some_arith) can be separated from the non learning bit which is just
a black box until later on.

If you start with arithmetic but have no way of trying out the
arithmetic yourself it's not a very hands on approach.  My first
lessons in C were not hampered by the fact that I didn't know 
what #include <stdio.h> did or why I wrote "int main(void)".
I just believed the book when it said they would be explained later,
and they were.

This addresses the problem of having no interactive query mechanism,
it's a little clumsy but not too bad unless you try to *explain*
everything straight away.

-- 
The quantum sort: 
	while (!sorted) { do_nothing(); }
Tyson Dowd   <tyson at tyse.net>   http://tyse.net/



More information about the users mailing list