문제

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?

도움이 되었습니까?

해결책

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)"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top