有没有办法将类型值转换为Char
Fay 中的数字 ASCII 代码?
(Haskell Prelude 提供了函数fromEnum
和等效函数ord
,但我在 Fay Prelude 中没有看到任何类似的东西。)
包的文档fay-base
记录了很多类型类,但由于 Fay 不支持类型类,我认为fromEnum
也不支持?
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)"