Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. type
  2. value
  3. type
  4. value
  5. ...
  6.  
  7. 0 -- code for a string value
  8. hello
  9. 70 -- code for an int value
  10. 10
  11. 0
  12. world
  13. 20 -- code for a double value
  14. 5.20
  15.  
  16. data KeyValue = forall a. (Typeable a, Show a, Eq a) => KeyValue (Int, a)
  17. instance Eq KeyValue where -- as I need to test equality
  18. KeyValue (code1, value1) == KeyValue (code2, value2) =
  19. code1 == code2 && case cast value2 of
  20. Just value2' -> value1 == value2
  21. Nohing -> False
  22.  
  23. parser :: Parser [KeyValue]
  24. parser = many' (keyValue <* endOfLine)
  25.  
  26. keyValue :: Parser KeyValue
  27. keyValue = do
  28. key <- decimal <* endOfLine
  29. value <- case key of
  30. 0 -> takeLine
  31. 20 -> double
  32. 70 -> decimal
  33. _ -> takeLine
  34. return $ KeyValue (key, value)
  35.  
  36. takeLine :: Parser Text
  37. takeLine = takeTill isEndOfLine
  38.  
  39. Couldn't match type Double with Text
  40. Expected type: Parser Text Text
  41. Actual type: Parser Double
  42. In the expression: double
  43. In a case alternative: 20 -> double
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement