Allowing duplicate instances in GHC 6.4

Robert van Herk rherk at cs.uu.nl
Fri Mar 25 08:33:24 EST 2005


Hi all,

I need to use duplicate instances. I read in the documentation on GHC 
6.4, that overlapping class instances checks are lazy instead of gready 
in 6.4. However, my code still gives duplicate instance errors when 
compiling in GHC 6.4.

Is the duplicate instance check still gready? Is there a way to 
overwrite that behaviour?

Right now, I have two instance of a class Datasource. Datasource allows 
the user to read (key,value) pairs.

class Datasource ds k v where
 ...

Now, I wanted to make a special datasource that combines two 
datasources, namely

data JoinedDS left right = JoinedDS left right
instance (Datasource left k v) => Datasource (JoinedDS left right) k v 
where
...

instance (Datasource right k v) => Datasource (JoinedDS left right) k v 
where
...

The idea is that when you combine 2 datasources in one JoinedDS, the 
user can read both types from the JoinedDS. I do not need to allow to 
combine 2 different datasources that have the same types of (key,value) 
pairs, so the duplicate instances will not occur and when they do, this 
will be by mistake. Hence, the two premisses in the instance declaration 
will never be fulfilled both at the same time and I do not want a 
duplicate instance error here.

Is there a  solution to this problem?

Thanks,
Robert


More information about the Glasgow-haskell-users mailing list