user17903042
user17903042

Reputation:

How can I parse hexadecimal string into Char in Haskell?

I am writing a parser using megaparsec and want to parse hex number to Char.

The hex number parser should take exactly two chars and return a char that has the same numeric value.

Right now I have something like this.

type Parser = Parsec Void String

pByte :: Parser Char
pByte = chr . read . ("0x" ++) <$> count 2 hexDigitChar

I heard that using read is considered bad practice.

Is there a built-in function that does something similar to this?

Upvotes: 1

Views: 533

Answers (0)

Related Questions