
19 May
2015
19 May
'15
5:12 a.m.
On Tue, May 19, 2015 at 12:03 PM, Anatoly Zaretsky
data Codes = A0100A | A0500A deriving Read
codeExists code = case reads code of [(_, "")] -> True _ -> False
Or with -XPatternGuards:
codeExists code | [(_, "")] <- reads code = True | otherwise = False
Oops, should have checked the types before posting: codeExists code = case reads code :: [(Codes, String)] of [(_, "")] -> True _ -> False Otherwise the compiler could not guess the right Read instance.