Convert Char to ASCII Code in Fay

Is there a way to convert type values Charto their ASCII numeric codes in Fay?

(Haskell Prelude offers a function fromEnumand an equivalent function ord, but I don't see anything like it in Fay Prelude.)

The documentation for the package fay-baseindicates many type classes, but since Fay does not support type classes, I assume it is fromEnumnot supported either?

+3
source share
1 answer

Data.Charis not in the fay database yet (see https://github.com/faylang/fay/issues/377 ), and there is only an enum instance for Int, but I will 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)"
+3
source

All Articles