instance overaps with lib

More about instance overlaps with the GHC library: I need to print in a special way the data of [Equation], (Term, Term), [(Term, Term)], (Equation, Equation). The first can be by defining showList in instance Show Equation. But Show has not a method of showPair. So, I need to write the function showsTermPair and to use it together with another home-made function showsListGeneric. And in ghc-6.4.1, it was sufficient to define the instances and to use only `shows'. About prompt feed-backs from users: this issue of possible fisfeature with overlaps does not look tragic. But with the Map library for Haskell-98, I take it as a considerable loss. It was said that I had a chance to make it standard, if asked about it in time. ----------------- Serge Mechveliani mechvel@botik.ru

On Tue, Sep 05, 2006 at 12:50:39PM +0400, Serge D. Mechveliani wrote:
More about instance overlaps with the GHC library:
I need to print in a special way the data of [Equation], (Term, Term), [(Term, Term)], (Equation, Equation).
The first can be by defining showList in instance Show Equation. But Show has not a method of showPair. So, I need to write the function showsTermPair and to use it together with another home-made function showsListGeneric.
You seem to be using special instances to do two things: add spacing and remove extraneous parentheses. A neater way to do the latter would be to use the precedence parameter of showsPrec for Term to control whether the parentheses are added in the first place, e.g. (untested) showsPrec p t = (case t of VarT v -> shows v App f [] [] -> showString (name f) App f [] [r] -> showParen (p > app_prec) $ showString (name f) . showChar ' ' . showsPrec (app_prec+1) r ... where app_prec = 10

On Tue, Sep 05, 2006 at 12:11:20PM +0100, Ross Paterson wrote:
[..] You seem to be using special instances to do two things: add spacing and remove extraneous parentheses. A neater way to do the latter would be to use the precedence parameter of showsPrec for Term to control whether the parentheses are added in the first place, e.g. (untested)
showsPrec p t = (case t of VarT v -> shows v App f [] [] -> showString (name f) App f [] [r] -> showParen (p > app_prec) $ showString (name f) . showChar ' ' . showsPrec (app_prec+1) r ... where app_prec = 10
Thank you very much. I have to study this. Because I always defined Show via showsPrec, and also was always missing of what is the first argument of showsPrec.
participants (2)
-
Ross Paterson
-
Serge D. Mechveliani