Why this cannot be compiled?

Hi, The following code failed to compiled, with error: Attribute.hs:46:91: Couldn't match expected type `[t]' against inferred type `(a, String)' In the expression: (color_, rest_) In a case alternative: [(color_, rest_)] -> (color_, rest_) In the expression: case reads rest1 of { [(color_, rest_)] -> (color_, rest_) _ -> (Color 0 0 0, rest1) } 43 instance Read Attribute where 44 readsPrec _ str = [ (mkAttr attr_ color, rest) | (attr_, rest1) <- lex str 45 , (color, rest) <- case reads rest1 of 46 [(color_, rest_)] -> (color_, rest_) 47 _ -> (Color 0 0 0, rest1) ] 48 where mkAttr "AttrFgColor" color = AttrFgColor color 49 mkAttr "AttrBgColor" color = AttrBgColor color 50 mkAttr "AttrInverse" _ = AttrInverse 51 mkAttr "AttrWeak" _ = AttrWeak 52 mkAttr "AttrUnderline" _ = AttrUnderline -- 竹密岂妨流水过 山高哪阻野云飞

Magicloud Magiclouds
43 instance Read Attribute where 44 readsPrec _ str = [ (mkAttr attr_ color, rest) | (attr_, rest1) <- lex str 45 , (color, rest) <- case reads rest1 of 46 [(color_, rest_)] -> (color_, rest_) 47 _ -> (Color 0 0 0, rest1) ]
Doesn't the (color,rest) pair in the list comprehension need to be pulled from a list? The case expression only returns a pair so you're basically left with [something| something, (color,rest) <- (somecolor,somerest) ] Since you're only producing a single (color,rest) for each rest1, you might consider lifting it out in the left side of the list comprehension. -k -- If I haven't seen further, it is by standing in the footprints of giants

Hum.... I must lost my mind....
Thank you.
On Mon, Jul 13, 2009 at 3:33 PM, Ketil Malde
Magicloud Magiclouds
writes: 43 instance Read Attribute where 44 readsPrec _ str = [ (mkAttr attr_ color, rest) | (attr_, rest1) <- lex str 45 , (color, rest) <- case reads rest1 of 46 [(color_, rest_)] -> (color_, rest_) 47 _ -> (Color 0 0 0, rest1) ]
Doesn't the (color,rest) pair in the list comprehension need to be pulled from a list? The case expression only returns a pair so you're basically left with [something| something, (color,rest) <- (somecolor,somerest) ]
Since you're only producing a single (color,rest) for each rest1, you might consider lifting it out in the left side of the list comprehension.
-k -- If I haven't seen further, it is by standing in the footprints of giants
-- 竹密岂妨流水过 山高哪阻野云飞
participants (2)
-
Ketil Malde
-
Magicloud Magiclouds