[Haskell-cafe] how to avoid overlapping instance error?
S. Alexander Jacobson
alex at alexjacobson.com
Mon Feb 28 05:50:59 EST 2005
If you are not using them to prevent overlapping instances, then why
require instance decls at all? For example, why does
GHC require an instance decl here:
instance (Ord x)=>ToSet  x where toSet = Set.fromList
But not here:
listToSet x = Set.fromList x
Or I suppose, one could rephrase this question as why not
simplify instance declarations to be:
instance ToSet where
toSet = Set.fromList
And let the typechecker take care of figuring out what instance is
being specified here?
S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
On Mon, 28 Feb 2005, Simon Peyton-Jones wrote:
> 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