a universal printer for Haskell?

RijkJ.C.vanHaaften RijkJ.C.vanHaaften
Mon, 18 Feb 2002 12:38:14 +0100


Hello,

Bernard wrote:
<<snip>>
>But the problem is not solved (drum roll please). Even first time programmers
>know the pitfalls of trying to show the empty list:
>
>    show [] ---> kapow!
>
>But you ought to be able to print the empty list,
>without having to make some bogus type qualification (which
>is in general not a solution to the problem of printing arbitrary values).

But how about the difference between
show ([] :: [Int] ) == "[]"
show ([] :: [Char]) == "\"\""

and

Prelude> (putStr.show) ([] :: [Int])
[]
Prelude> (putStr.show) ([] :: [Char])
""

You probably want the first, but I want the
second in the cases I'm working with strings.

This problem is apparently not solved by simply
adding a defaulting meganism for Show or Reify
or whatever.

It's not clear to me how much your proposal
differs from extending the default meganism
(http://www.haskell.org/onlinereport/decls.html#default-decls)
to allow arbitrary classes, rather than only
class Num, which would be more consistent
with the current Haskell 98.
Do Ghc and/or Hugs allow other defaults then
Num already?

Regards,

Rijk-Jan van Haaften