[Haskell-cafe] How to "Read" this?
Magicloud Magiclouds
magicloud.magiclouds at gmail.com
Tue Jul 14 01:49:01 EDT 2009
Hi,
I have a data structure, which shows like this: AttrBgColor {bgColor
= Color 0 0 0}
And the following is my Read code. But it failed parsing....
31 instance Read Attribute where
32 readsPrec _ str = [ (mkAttr attr_ color, rest) | (attr_, rest1) <- lex str
33 , (color, rest)
<- if (isPrefixOf " {bgColor = " rest1)
34
|| (isPrefixOf " {fgColor = " rest1)
35
then case reads $ drop 12 rest1 of
36
[(color_, rest_)] -> [(color_, rest_)]
37
_ -> [(Color 0 0 0, rest1)]
38
else [(Color 0 0 0, rest1)] ]
39 where mkAttr "AttrFgColor" color = AttrFgColor color
40 mkAttr "AttrBgColor" color = AttrBgColor color
41 mkAttr "AttrInverse" _ = AttrInverse
42 mkAttr "AttrWeak" _ = AttrWeak
43 mkAttr "AttrUnderline" _ = AttrUnderline
--
竹密岂妨流水过
山高哪阻野云飞
More information about the Haskell-Cafe
mailing list