[Haskell-cafe] Read Instance code.

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Sat Jul 3 07:28:48 EDT 2010

Andy Stewart <lazycat.manatee at gmail.com> writes:

> Hi all,
> I have some incorrect "Read instance" make i got error "Prelude.read: no
> parse", and i don't know how to fix it. 
> newtype SerializedWindow = SerializedWindow (Maybe DrawWindow)
> instance Show SerializedWindow where    
>   show _ = "SerializedWindow Nothing"
> instance Read SerializedWindow where           
>     readsPrec _ str = [(SerializedWindow Nothing, idStr) 
>                            | (val :: String, idStr) <- reads str]

Try using Derive or DrIFT to generate a proto-typical instance for you,
and then hack that and make it neater.  If you don't care about
cross-compiler compatability, using ReadP rather than ReadS also results
in nicer parsing code.

Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com

More information about the Haskell-Cafe mailing list