[Haskell-cafe] how to avoid overlapping instance error?

Simon Peyton-Jones simonpj at microsoft.com
Sun Feb 27 22:01:54 EST 2005

Unfortunately, the context of an instance decl is not taken into account
when matching instance decls.  Yes, it would make sense to do so, but
it'd make the system yet more complicated.

So Show (table item) overlaps with Show ([] item)

Overlap is checked lazily, so if you look for Show (MyTable t) you won't
get overlap. Only if you ask for Show (table item), where the type
checker still doesn't know what type 'table' is going to be, do you get
a problem.


| -----Original Message-----
| From: haskell-cafe-bounces at haskell.org
[mailto:haskell-cafe-bounces at haskell.org] On Behalf Of S.
| Alexander Jacobson
| Sent: 25 February 2005 17:09
| To: haskell-cafe at haskell.org
| Subject: [Haskell-cafe] how to avoid overlapping instance error?
| Currently, the HAppS.DBMS lib requires the user to provide a Show
| instance for their table types.  An example might be:
|     instance (Show item) => Show (MyTable item) where
|         showsPrec d table = showsPrec d $ Set.toList $ myTableSet
| But the Table class itself defines a toSet function so I think I
| should be able to do this once for all Table instances:
|     instance (Show item,Ord item, Table table item p) => Show (table
item) where
|         showsPrec d table = showsPrec d $ Set.toList $ toSet table
| But I get an error telling me I am overlapping with Show [a].
| Since [] is not an instance of Table, I don't see why there should be
| an overlap.
| -Alex-
| ______________________________________________________________
| S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
| _______________________________________________
| Haskell-Cafe mailing list
| Haskell-Cafe at haskell.org
| http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list