Hi Peter,
| A suggestion for a small tweak in the toplevel loop
| which would improve things for me:
| That is to make the output option to
| "Use 'show' if you can"
| and then to default to the built-in printer for those types
| that are not in class Show. When one does start
| building trees and complex structures we can then
| have the best of both worlds: they will be able to be
| externalized even though we haven't learned
| to write nice show routines yet, but when we do
| write the routines, they will be used.
Unfortunately, there's a problem with this: the built-in
printer doesn't/can't use any user-defined Show instances.
Suppose that you have code like the following:
data T = ...
instance Show T where ... -- Format T values
data Tree a = ... -- No Show instance here.
With your proposal, a value of type T would print using
the special show function, but all the T elements in a
value of type Tree T would print using the built-in
printer's rendition of the T datatype! The illusion that
T values are displayed in a special way would be spoiled.
I wonder why the built-in printer isn't good enough for
your needs in this case ... for what types is a special
version of Show actually needed? Perhaps it would be
possible to tackle your problem more directly by improving
the built-in printer to deal with those cases.
Another possibility to consider: At some point in the past
few years, the built-in printer was modified to prefix
datatype constructors with type names, as in "Maybe_Just".
I think there was probably some good justification for this,
but perhaps it is another reason for your dissatisfaction
with the built-in printer? Maybe there should be a flag
to switch off the prefix so that things are easier for
beginners to work with.
A final alternative is simply to tell your students about
the magic incantation "deriving Show", which they should
append to any datatype definition if they want to be able
to print values of the newly defined type. You can actually
go quite a long way in using type classes like this without
ever showing them a class or instance declaration ...
Some ideas for the current stewards of Hugs, and, I hope,
for you too!
All the best,
Mark