Question

Is there a way to convert values of type Char to their numerical ASCII codes in Fay?

(The Haskell Prelude offers the function fromEnum and the equivalent function ord, but I don't see anything similar in the Fay Prelude.)

The documentation for the fay-base package notes a lot of type classes, but since Fay doesn't support type classes, I assume that fromEnum is not supported either?

Was it helpful?

Solution

Data.Char isn't in fay-base yet (see https://github.com/faylang/fay/issues/377) and there is only an enum instance for Int, but I'll add ord and chr. Here's how to do it until then:

chr :: Int -> Char
chr = ffi "String.fromCharCode(%1)"

ord :: Char -> Int
ord = ffi "%1.charCodeAt(0)"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top