I'm writing a JSON parser in Haskell but I'm having trouble parsing unicode values. If I want to convert \u2013 to a character, I can just wrap it in quotes in Python and I get '–'. I'm having trouble figuring out how to do the same in Haskell. If I wrap it in quotes, I get the error "lexical error in string/character literal at character 'u'" If I run putStrLn "\2013", I get the character 'ߝ'. How can I get the '–' character in Haskell?
1 Answer
Plain digits is base 10; for base 16, use the x prefix.
> putStrLn "\x2013" – BUT you shouldn't need to know this. Use aeson for your JSON parsing needs.
1 Comment
noatbfgtxa
Thank you, this worked. I'm trying to make a JSON parser mostly as a learning exercise but thanks for the recommendation.
\u2013to extract the integer value8211and useData.Char.chr :: Int -> Charon it.