Home > Software engineering >  Convert Unicode value to Char in Haskell
Convert Unicode value to Char in Haskell

Time:10-15

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?

CodePudding user response:

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.

  • Related