"Rustom P. Mody" <[EMAIL PROTECTED]> recommends
>data Tree a where
> Leaf :: a -> Tree a
> Br :: a -> Tree a -> Tree a -> Tree a
rather than
>data Tree a = Leaf a
> | Br a (Tree a) (Tree a)
as it is less confusing for beginning students.
It all depends how you teach it.
The major problem teaching beginning students, many of whom have never
programmed before, is the initial "Eureka" step. Computer Science in
general does not really have a programming methodology to solve this
problem. Functional programming does.
As an example, consider an assignment for such a student asking for all the
values of a tree to be incremented.
What can the teacher do to help the student to know where to start? I need
a mindless method for the student to follow until he or she gets a feel for
the technology.
1) Name the function
inctree
2) Type the function, especially input types (not too much brain for simple
examples)
Tree a -> Tree a
3) Based on the type definition(s) of the input(s), write down (no brain)
the LHS patterns
Leaf value =
Br value (Tree left) (Tree right) =
4) Using usually a little brain, deal with the simple case
Leaf (value + 1)
5) Using more brain, deal with the harder ("Eureka") case.
It is thus possible to get even the most apprehensive student to quickly
produce the skeleton of the answer, before concentrating on the real bit of
the problem. This is exactly what is needed, as such students usually focus
on the real bit first and quickly become confused.
The important thing is that different data definitions would make step 3
much more difficult, as the correspondence would be less apparent.
The method has good software engineering properties, as partial functions
are strongly discouraged.
It is also good declarative programming.
I think it was such arguments that persuaded my software engineering
colleagues that a functional language was acceptable as the first language.
-------
Hugh Glaser, Declarative Systems Laboratory
Department of Electronics and Computer Science,
University of Southampton,
Southampton SO9 5NH
Tel: +44 703 593670, Fax: +44 703 593045