[Haskell-cafe] Duplicate instance declaration

Twan van Laarhoven twanvl at gmail.com
Thu Mar 22 16:02:26 EDT 2007

Bas van Dijk wrote:
> ....
> I would also like to get the formatting constraints working. However
> the solution in the code below gives a  "Duplicate instance
> declarations" error. If I -fallow-overlapping-instances than the type
> checker goes into an infinite loop.
> I would like to know why this is happening and if there's a way to fix it.

You have multiple instances with the same instance head (the part after 
the =>). Haskell doesn't look at the context when deciding what instance 
to use, so they overlap.

An alternative idea would be to use data types instead of classes for 
the registers and memory locations

 > data Reg size tag = Reg
 > data EAX_ -- dummy type, not exported
 > -- only export this
 > type EAX = Reg Bit32 EAX_
 > eax :: EAX
 > eax = Reg

and similairly for memory

 > data Mem size tag = Mem Word32
 > data Mem32_ -- dummy type, not exported
 > type Mem32 = Mem Bit32 Mem32_

Now you can have the instances

 > instance MovFormat (Reg size a) (Reg size b)
 > instance MovFormat (Reg size a) (Mem size b)



More information about the Haskell-Cafe mailing list