instance overlap in 6.6 candidate
Serge D. Mechveliani
mechvel at botik.ru
Tue Sep 5 03:42:00 EDT 2006
On Mon, Sep 04, 2006 at 03:39:06PM +0100, Simon Peyton-Jones wrote:
> | ------------------------------------------------
> | data Equation = ...
> | instance Show Equation where ...
> |
> | instance Show [Equation]
> | where
> | showsPrec _ eqs = <certain program which prints a list of equation
> | in a `nicer' way than by the default list
> printing
> | >
> | ------------------------------------------------
> |
> | This gives the user possibility to redefine a certain part of the
> | library instance.
> | Is not ghc-6.4.1 better at this point?
>
> Perhaps. That's what I'd like feedback about.
Let me exlain a bit more the reason.
show [1, 2, 3] = "[1,2,3]" -- all right, let it be.
Now, for the list eqs :: [Equation], the GHC instance prints it, for
example, as
-------------------
[[21] n+0 = 0 (Parents [[1],[2]]),[22] n+(s n) = s (n+m) (Parents [[33],
[44]]),[23] n*0 = 0 (Parents [[],[]])]
-------------------
And I would like it to be at least
--------------------
[[21] n+0 = 0 (Parents [[1],[2]]),
[22] n+(s n) = s (n+m) (Parents [[33],[44]]),
[23] n*0 = 0 (Parents [[],[]])
],
--------------------
which is easier to read. I decided that to overlap with the ghc instance
is the simplest and best solution.
I thank Ian Lynagh <igloo at earth.li> who suggests
L> instance Show Equation where
L> showsPrec _ eq = ...
L> showList eqs = <certain program which ...>
Indeed. I even wrote a showsList function, without knowing of the
showsList class method!
But as Ian writes,
L> This doesn't address the general issue
So far, I tried this overlap only for Show List and Show Pair,
but probably, users and myself would like to partially redefine some other
library instances.
Simon Peyton-Jones writes
> (Incidentally, 6.5 has been like this for about a year without
> complaints.
I am sorry for this, I am slower than GHC. I have been with 6.4.1 last
1-2 years, and ignored the further version matters. Finally, a week ago
decided to look into what is coming with 6.6.
> Also I made the change because people wanted to be able to
> *use* overlapping instances (defined in a library) without having to
> give the -fallow-overlapping-instances flag.)
The difference for me is to have a little bit less-or-more comfort.
DoCon-2.09 has ported from 6.4.1 to 6.6-candidate only by removing
the `data' name from `dependencies', and it looks like working all right.
In Dumatel-1.06, it reports the error of this library overlap for `Show'.
For exampl, I can define the showsList method, as Ian suggests.
Generally, I suspect that ghc-6.4.1 is better at this point of library
overlaps, but I am not sure.
Anyway, the GHC developers have now more of feedback, they know better
and can decide.
Thanks,
-----------------
Serge Mechveliani
mechvel at botik.ru
More information about the Glasgow-haskell-users
mailing list