Data.Set and instance Read (Set a)

Dear library maintainers, I have come across a conflict with the Data.Set library, namely that its definition of the instance of Read assumes the default instance for reading lists: instance (Read a, Ord a) => Read (Set a) where readsPrec p = readParen (p > 10) $ \ r -> do ("fromList",s) <- lex r (xs,t) <- reads s return (fromList xs,t) The conflict arises when I define my own instance for reading a non-polymorphic list, like in: instance Read [SomeType] Then Hugs protests that: ERROR file:{Hugs}\packages\base\Data\Set.hs:542 - Cannot justify constraints in instance member binding *** Expression : readsPrec *** Type : Read (Set a) => Int -> ReadS (Set a) *** Given context : Read (Set a) *** Constraints : Read [a] Fortunately, I do not need the Data.Set library, and can prevent the problem by an explicit empty import: import Data.Set () However, a simple fix for it might be welcome by others as well: instance (Read a, Read [a], Ord a) => Read (Set a) where ... Thanks for you attention. Best regards, Otakar Smrz

Otakar Smrz schrieb:
The conflict arises when I define my own instance for reading a non-polymorphic list, like in:
instance Read [SomeType]
1.) This is not haskell98 2.) should not readList be defined rather than readsPrec? instance Read SomeType where readList ...
Fortunately, I do not need the Data.Set library, and can prevent the problem by an explicit empty import:
import Data.Set ()
Can't you omit the whole line (if sets are not involved)?
However, a simple fix for it might be welcome by others as well:
instance (Read a, Read [a], Ord a) => Read (Set a) where ...
"Illegal Haskell 98 class constraint in instance declaration" There is an instance: instance Read a => Read [a] so the given "instance (Read a, Ord a) => Read (Set a)" would overlap. (Per type only one instance can be used.) I hope I did not completely missunderstood you Christian
participants (2)
-
Christian Maeder
-
Otakar Smrz