[Haskell-cafe] Why this cannot be compiled?

Ketil Malde ketil at malde.org
Mon Jul 13 03:33:09 EDT 2009

Magicloud Magiclouds <magicloud.magiclouds at gmail.com> 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.

If I haven't seen further, it is by standing in the footprints of giants

More information about the Haskell-Cafe mailing list