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

Georg Martius mai99dgf at studserv.uni-leipzig.de
Thu Oct 20 08:57:23 EDT 2005


Hi Malcolm,

Thanks for checking in the stuff. However, I am really sorry, but my code 
contains a bug!
Example: "{Foo:=-0.9,...}"
Problem: "lex" parses ":=-" as one lexeme
Solution: parse ":=" explicitly
Please replace the readPair function with the following one, unless you have a 
better idea.

-- parses a pair of things with the syntax a:=b
readPair :: (Read a, Read b) => ReadS (a,b)
readPair s = do (a, ct1)    <- reads s
                -- we cannot use lex to parse ":=" 
                -- because for "Foo:=-0.9" the ":=-" would be lexed together
                ((), ct2)   <- readcolonequal ct1 
                (b, ct3)    <- reads ct2
                return ((a,b), ct3)
    where readcolonequal (' ':xs) = readcolonequal xs
          readcolonequal (':':'=':xs) = [((),xs)] 
          readcolonequal _ = []

Regards,
	Georg

Am Donnerstag, 20. Oktober 2005 13:00 schrieb Malcolm Wallace:
> Georg Martius <mai99dgf at studserv.uni-leipzig.de> writes:
> > I have just looked at your Read instance for Data.Set and implemented an
> > instance for Data.Map in the same manner.
>
> OK, checked in.
> Regards,
>     Malcolm
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries

-- 
---- Georg Martius,  Tel: (+49 34297) 89434 ----
------- http://www.flexman.homeip.net ---------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/libraries/attachments/20051020/47854018/attachment.bin


More information about the Libraries mailing list