[Haskell] Read Instances for Data.Map and Data.Set

Donald Bruce Stewart dons at cse.unsw.edu.au
Sat Oct 22 01:21:08 EDT 2005

> On 21 October 2005 08:43, Johannes Waldmann wrote:
> > Georg made the point that if a type is an instance of Show,
> > then it should also be an instance of Read, and  read . show == id
> I rather think that this should be an explicit design requirement for
> Read/Show instances in the libraries, along with the requirement that
> the Show instance outputs valid Haskell syntax that can be included in a
> program (assuming appropriate imports, and possibly an appropriate type
> signature).  Show is not for pretty-printing, it is for serialising.
> Are there any Show instances that violate these requirements in the
> base/haskell98 packages currently?

The ones I can think of off the top of my head. Of course, these are
weird for various reasons though:

    > show $ toDyn (1::Int)     -- Dynamic has no Read
    > show $ typeOf (1::Int)    -- TypeRep as no Read

    PackedString has no Read, but could have one. Due to Autrijus:
        instance Read FastString where
            readsPrec p str = [ (pack x, y) | (x, y) <- readsPrec p str ]

    or some tricky packed version a la Binary and .hi files.

None of these is terribly troubling though, I think.

-- Don

More information about the Libraries mailing list