map and fmap

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Thu Aug 17 11:12:15 EDT 2006


On 2006-08-15 at 12:38+0200 John Hughes wrote:
> From: Robert Dockins <robdockins at fastmail.fm>
>  
> 
>     On Aug 14, 2006, at 3:00 PM, Iavor Diatchki wrote:
> >> and I think, that a better approach to problems like these would be to
> >> have a simplified "learning Prelude" for the beginners class, rather
> >> than changing the standard libraries of the language (writing type
> >> signatures probably also helps...)
> 
>     This idea has been kicked around a few times, but, AFAIK, it's never
>     really been fleshed out. Has anyone ever put anything concrete on
>     the table? It seems to me that most complaints are about hard-to-
>     understand error messages, and these almost always arise from
>     typeclasses. They are especially confusing when they arise from
>     syntax sugar. I suppose a prelude with no typeclasses and compiler
>     options to make all syntax non-overloaded would be one way to start.
>     On a related note, I've seen a number of Haskell design decisions
>     justified by the "beginners find it difficult" argument. Is this
>     argument really valid? Is there any reason not to just tell
>     beginners to use Helium? Is there a case for something between
>     Helium and full H98 (or H')? 
> 
> I have a lot of experience of teaching beginners--I've
> been doing it for years,

I'm sure your observations are correct, and it makes a
convincing argument, but I don't buy it completely.

> [...]
> Now, this approach couldn't work if the language I taught
> really WAS only suitable for toy programs!

Granted.

> Even a "beginner's prelude" would introduce a
> discontinuity for students, making it harder to take the
> step from course exercises to real programs, and that
> would mean that fewer of my students would end up as
> Haskell enthusiasts. I'd be very sad about that.

That would be something to be sad about if true, but it
doesn't convince me that there is no solution. 

Here's what I would like to see:

• Pare the standard prelude down to the bare minimum
  necessary to give types to the basic syntax of the
  language. So 

  ‣ no Int or Double, just Integer and Ratio Integer, so
    that constants can be explained. 

  ‣ Given that I'm accepting most of your argument, we'd
    have to have List rather than giving [|] and friends
    overloaded types -- I don't like that, but I can live
    with it.

  ‣ no operations on anything. (Are there any that
    absolutely have to be in the prelude?)

• Move all the operations on Lists into List, all arithmetic
  into Integer, Int, Double, Float (or rather
  Arithmetic.Integer etc, and possibly have Arithmetic too
  -- being able to import a bundle of libraries at one go
  seems sensible). Similarly IO and so on.

Now a typical Haskell programme would begin with with a
whole bunch of import statements -- but then all but toy
programmes do anyway, and using the same style doesn't seem
to have caused C any problems.

The "beginners' prelude" would then consist of several
modules that provided classless versions of the troublesome
overloaded functions, each to be replaced by the real thing
when the source of the trouble had finally been taught. So
what I'm proposing doesn't avoid your objection about a
discontinuity -- in fact it introduces more, but my hope
would be that several small discontinuities rather than one
big one would be sufficiently little trouble. I'll grant
that this is the "telling lies to children" approach to
teaching, but teaching people Newtonian mechanics before
Einsteinian is generally what happens, and the advantage is
that where it applies it works almost as well as Einstein's
version, and is practical. The same would be true of the
beginners' prelude: folk who only got as far as doing
arithmetic on Integers and Rationals with some simple stuff
on Lists could go on using the simplest beginners' prelude
indefinitely.

True, you'd have to tell your students early on that they
had to put some mumbo-jumbo (import Foo) at the beginning of
their first programmes, but way back in the mists of time I
was taught to programme in some language or other with just
such an incantation, and I'm sure it caused no
problems. Most students are quite happy to follow some
instructions blindly at first (and the ones who aren't are
usually capable of quickly understanding what the
mumbo-jumbo does).


-- 
Jón Fairbairn                              Jon.Fairbairn at cl.cam.ac.uk




More information about the Haskell-prime mailing list