I'm using the following typeclass:
module T where
class T a where
v :: a
An instance of T Int
that I implemented:
import T
import A (av)
instance T Int where
v = 0
main = putStrLn (av ++ show v)
And a module that I want to use a value from, which also has an instance of T Int
.
module A where
import T
instance T Int where
v = 0
av = "value from A"
The problem is this doesn't work:
$ runghc Main.hs
Main.hs:4:9:
Duplicate instance declarations:
instance T Int -- Defined at Main.hs:4:9-13
instance T Int -- Defined at A.hs:3:9-13
Haskell complains that there are 2 declarations for the same instance. How can I tell him not to import the instance from B
, or to unify both instances, or to only use the instance from Main
?
T
orB
, but I want to use a value fromB
, and I want to make an instance ofT
. – Dognewtype
wrapping the existing type and write your instance for thenewtype
instead. – hammar