Created
April 8, 2015 14:25
-
-
Save chemist/59a1b1092337beb57108 to your computer and use it in GitHub Desktop.
parser battle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Passport = Passport Word8 Word32 | |
parsePassport :: Parser (Either ByteString Passport) | |
parsePassport = good <|> bad | |
where | |
bad = Left <$> takeWhile (/= '\n') <* endOfLine | |
good = Right <$> (Passport <$> label <*> body <* endOfLine) | |
where | |
label = fromIntegral . digitToInt <$> digit | |
body = do | |
x <- decimal <* char ',' | |
y <- decimal | |
return $ x * 1000000 + y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment