Data.Tree.Tree Show instance

Johannes Waldmann joe@informatik.uni-leipzig.de
Tue, 12 Aug 2003 12:30:27 +0200 (CEST)


On Mon, 11 Aug 2003, Tomasz Zielonka wrote:

> The Tree datatype in new Data.Tree module has a Show instance ...

I agree that Read/Show should normally come as a pair.
It is debatable whether a library should contain a Show instance
that makes it rather impossible to write the corresponding Read instance.

Even more so since no library user can later change this:
by the Haskell definition,
if you import a module that contains a data type definition,
then you also inherit all its instances from that module.
(Section 5.4 of the report, http://haskell.org/onlinereport/modules.html)
the workaround would be to move the `instance Show Tree'
into a separate library module.


On the other hand, it is my opinion that for a clean program design,
you should normally define your own `data' (or `newtype') types, 
rather than use exisiting ones by `type' synonyms.

this may lead to somewhat larger program texts,
but you'll find that they are more readable, and extendable.
(Compare adding another component to a tuple, and to a record).

this also gives you the opportunity 
to define class instances in any way you want.


best regards,
-- 
-- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ --
-- joe@informatik.uni-leipzig.de -- phone/fax (+49) 341 9732 204/209 --