[mercury-users] Mercury needs a Tutorial

Peter Schachte schachte at cs.mu.OZ.AU
Tue Feb 16 11:14:49 AEDT 1999


On Fri, Feb 12, 1999 at 04:50:59PM +1100, Tyson Dowd wrote:
> On 12-Feb-1999, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:

> > 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 is about what I was thinking of if no one wants to get read/3 to
work for preds.  But why not hide the main completely to begin with.
You could supply a source file like the following with the tutorial:

	:- module tutorial_harness.
	:- interface.
	:- pred main(io__state::di, io__state::uo) is det.
	:- implementation.

	main -->
		{ tutorial(X) },
		io__print(X).
		io__print("\n").

	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Don't explain it at all at first, just tell them what to add at the
end of the file to define tutorial/1 for each example.  maybe the
first example would be just

	tutorial(X) :- 
		X = 2 + 2 * 3.

Second maybe

	tutorial(X) :- 
		2 + 2 * 3 = X.

to observe that = *really* means equal.  And so on, as I suggested
initially.  I forgot to mention disjunction, if-then-elses, negation,
multi-clause predicates, and DCGs.

But it really *would* be a lot easier if you could just type code and
clauses into a Mercury top level and see what happens.

-- 
Peter Schachte                     The significant problems we face cannot
mailto:schachte at cs.mu.OZ.AU        be solved by the same level of thinking
http://www.cs.mu.oz.au/~schachte/  that created them.
PGP: finger schachte at 128.250.37.3      -- attributed to Albert Einstein 



More information about the users mailing list