Skip to content

Instantly share code, notes, and snippets.

@chemist
Created April 8, 2015 14:25
Show Gist options
  • Save chemist/59a1b1092337beb57108 to your computer and use it in GitHub Desktop.
Save chemist/59a1b1092337beb57108 to your computer and use it in GitHub Desktop.
parser battle
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