3

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?

AndrewC
  • 32,300
  • 7
  • 79
  • 115
Heinrich Apfelmus
  • 11,034
  • 1
  • 39
  • 67

1 Answers1

3

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)"
Adam Bergmark
  • 7,316
  • 3
  • 20
  • 23