Data.Set and instance Read (Set a)

Otakar Smrz otakar.smrz at
Wed Jun 20 21:12:17 EDT 2007

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

More information about the Libraries mailing list