Haskell's syntax

Paul Hudak paul.hudak@yale.edu
Tue, 22 Apr 2003 10:24:47 -0400

Of these I think that (3) is most serious.  What I do is tell students
that a data type declaration such as:

  data Tree a = Bin (Tree a) a (Tree a) | Nil

is really a kind of shorthand for:

  data Tree a where
    Bin :: Tree a -> a -> Tree a -> Tree a
    Nil :: Tree a

which better separates the worlds of types and terms (and happens to
look like a type class declaration).

Hope this helps,  -Paul   

Arjan van IJzendoorn wrote:
> Hello everyone,
> I teach Haskell to our first-year students and I find that Haskell's syntax
> is confusing to many. Some examples:
> (1) You define data types with vertical bars (|) but in the world of
> expressions vertical bars (i.e. guards) are exactly what you can not use to
> discriminate between constructors.
> (2) Pattern-matching and guards are very often mixed up. Both are used for
> making choices and they overlap somewhat but not completely in expression
> power. For learning a language it would be nice if one construct did it all,
> guards including pattern guards maybe.
> (3) Types and expressions look very much alike. Say we have:
>   data Tree a = Bin (Tree a) a (Tree a) | Nil.
> Around half (!) of the students now write (on a written test):
>   size (Bin (Tree left) x (Tree right)) = ...
> mixing up the two worlds completely.
> Do other teachers have the same experience?
> Regards, Arjan