3

有没有办法将类型值转换为CharFay 中的数字 ASCII 代码?

(Haskell Prelude 提供了函数fromEnum和等效函数ord,但我在 Fay Prelude 中没有看到任何类似的东西。)

包的文档fay-base记录了很多类型类,但由于 Fay 不支持类型类,我认为fromEnum也不支持?

4

1 回答 1

3

Data.Char还没有在 fay-base 中(参见https://github.com/faylang/fay/issues/377)并且只有一个枚举实例Int,但我会添加 ord 和 chr。在此之前,如何做到这一点:

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

ord :: Char -> Int
ord = ffi "%1.charCodeAt(0)"
于 2014-02-23T01:44:29.257 回答