Michael (& the Haskell mailing list) --- I empathise with your remarks:
we're in the process of switching our teaching from using Miranda to
Haskell/Hugs & your comments prompted me to mail my colleagues with a few
questions (copy below). The Haskell language is intended for allcomers but
the Haskell Report is not (as it says) a tutorial. In introducing new
students (both beginners and old-elsewhere) we need to have some sort of
linear route through a language's syntax, semantics, styles, pragmatics
etc --- if I want to talk about zip and unzip before mentioning foldr,
lambda abstractions or irrefutable patterns then either I use it without
definition or use a more ``mundane'' definition (which is what I do ---
see below).
The textbooks by Bird and Thompson both do this (they don't even mention
the Haskell Report definitions of zip and unzip); the ``Gentle
Introduction'' talks about ``Lazy patterns'' (which are irrefutable);
Thompson uses the term ``conformal'' for definitions of the form
(a,b) = f y (but I can't find that term in the Report --- I think it
uses the term ``pattern binding'')
---
I guess any documentation project should aim to fill the gap between the
introductions and the Report.
Cheers --- Phil
On Wed, 8 Sep 1999, Michael T. Richter wrote:
> >> unzip = foldr (\(a,b) ~(as,bs) -> (a:as,b:bs)) ([],[])
>
> >> Not exactly intuitive. Could be better. I'm assuming that George's point
> >> is that this documentation leaves plenty of room for expansion.
>
> As a new user (and a complete newbie to FP), perhaps I can shed some light
> on something here....
> - The above "explanation" is worthless.
> - It is completely and absolutely worthless.
> - Indeed "explanations" like this cause more harm than good.
> - In that they have no good qualities at all, but can cause harm.
>
>From [EMAIL PROTECTED] Thu Sep 9 10:41:12 1999
Date: Thu, 9 Sep 1999 09:17:00 +0100 (BST)
From: Phil Molyneux <[EMAIL PROTECTED]>
To: Dan Russell <bs_s477@kingston>, Barry Avery <B.Avery@kingston>,
Chris Reade <[EMAIL PROTECTED]>
Subject: unzip
Hi There Softdev staff --- If you've been following the Haskell mailing
list you'll have been reminded of the Prelude definition of ``unzip''
unzip :: [(a,b)] -> ([a],[b])
unzip = foldr (\(a,b) ~(as,bs) -> (a:as,b:bs)) ([],[])
zip :: [a] -> [b] -> [(a,b)]
zip = zipWith (,)
Questions:
(1)
Where in the Haskell Report is the (,) constructor documented ?
[Most beginners might look for a ``,'' operator, not a ``pair''
constructor]
(2)
Why must the second argument to the lambda abstraction be irrefutable (and
what does irrefutable mean ?
[I don't want to have to talk about the difference between bottom and pair
of bottoms on a first year course]
(3)
Following on from irrefutable, what's the difference between ``binding a
value to a pattern'' and ``evaluation''
(4)
Given that zip and unzip are so useful (see exercise sheets and exam
questions passim), are we going to introduce these with more mundane
definitions (see the Miranda manual for example) and are we going to have
to talk about irrefutable patterns ?
Mundane Definitions of zip and unzip:
zip :: [a] -> [b] -> [(a,b)]
zip (a:xs) (b:ys) = (a,b) : zip xs ys
zip xs ys = []
(this is zip2 in Miranda)
unzip :: [(a,b)] -> ([a],[b])
unzip [] = ([],[])
unzip (a,b):ps
= (a:as,b:bs)
where
(as,bs) = unzip ps
Question: How do you get the lambda abstraction out of the mundane
definition of unzip ? (and no hand waving --- I want something that could
be marked by SPJ in one of his famous exams :-)
Question: Are we going to talk about lambda absractions on the course ?
I'm just finishing the Module Guide & I think we should review the course
as we go along every few weeks --- there are quite a few things around
like this.
Note that neither Thompson nor Bird defines unzip in the same way as the
Haskell prelude. Mind you it certainly tests whether you really understand
the difference between foldl and foldr (Dan: how do you express one in
terms of the other ??)
Cheers --- Phil
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Phil Molyneux email [EMAIL PROTECTED]
work tel 0181 547 2000 x 5233 home tel 0181 549 0045
Kingston Business School WWW http://www.kingston.ac.uk/~bs_s024
Kingston University, Kingston Hill, Kingston-upon-Thames KT2 7LB, UK
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~