Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- value
- type
- value
- ...
- 0 -- code for a string value
- hello
- 70 -- code for an int value
- 10
- 0
- world
- 20 -- code for a double value
- 5.20
- data KeyValue = forall a. (Typeable a, Show a, Eq a) => KeyValue (Int, a)
- instance Eq KeyValue where -- as I need to test equality
- KeyValue (code1, value1) == KeyValue (code2, value2) =
- code1 == code2 && case cast value2 of
- Just value2' -> value1 == value2
- Nohing -> False
- parser :: Parser [KeyValue]
- parser = many' (keyValue <* endOfLine)
- keyValue :: Parser KeyValue
- keyValue = do
- key <- decimal <* endOfLine
- value <- case key of
- 0 -> takeLine
- 20 -> double
- 70 -> decimal
- _ -> takeLine
- return $ KeyValue (key, value)
- takeLine :: Parser Text
- takeLine = takeTill isEndOfLine
- Couldn't match type Double with Text
- Expected type: Parser Text Text
- Actual type: Parser Double
- In the expression: double
- In a case alternative: 20 -> double
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement