How can I parse hexadecimal string into Char in Haskell?

411 views Asked by At

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?

0

There are 0 answers