Teaching (was: defaults)

Benjamin Franksen benjamin.franksen at bessy.de
Thu Nov 30 13:07:47 EST 2006

Malcolm Wallace wrote:
> Unfortunately, I suspect that teaching is _the_ major use-case for
> defaulting.  Imagine, day one, lesson one, a student types
>     Prelude> 1+2
> into Hugs, and gets the response
>     Unresolved overloading: Num a
> Huh?  This is lesson one, and you already need to tell students about
> type classes and overloading, before you have even covered simple
> expressions fully?  I am certain this is the reason why defaulting was
> introduced.

I remember someone proposing a Beginner's Prelude. Such a Prelude could
solve almost all the teaching problems that are regularly brought against
making the language or the standard libraries more generic and orthogonal
(and thus more useful for the experienced programmer, and additionally to
those of us who, even as beginners, rather accept "apparent weirdness, as
long as [they] could [eventually] discover the elegant reason behind it",
as Ashley so nicely put it). Witness the eternal 'map' vs. 'fmap' argument:
Beginner's Prelude could define map::(a->b)->[a]->[b] and /not/ import the
Functor class, whereas serious users would import Control.Functor or
whatever and have the more generic map from class Functor.

In the particular case that's been discussed here (defaulting), the solution
is to have Integer be the only integral type in the new Prelude.

It has also been argued that the experienced programmer doesn't need any
Prelude at all, she can import all the stuff she needs explicitly; the
penalty for that would be small since any non-trivial piece of code needs
to import lots of modules explicitly anyway. The logical consequence is to
rename Beginner's Prelude back to just Prelude. One proposal I remember was
to implicitly import the Prelude (and I'd say this should be the stripped
down Beginner's version) only for modules with no 'module Main' header
which I think is a nice compromise and could also be the default if you
fire up ghci or hugs without arguments. Of course one can also import
Prelude explicitly, if desired.


More information about the Haskell-prime mailing list