在 Haskell 中,函数Data.Char.isAlpha
检查一个字符是否是字母,但也是如此Data.Char.isLetter
。这些功能之间有什么真正的区别,或者它们可以互换吗?
看着sources http://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/src/Data-Char.html它们看起来是等价的。
这是定义isLetter
如 4.3.1.0 中定义
-- derived character classifiers
-- | Selects alphabetic Unicode characters (lower-case, upper-case and
-- title-case letters, plus letters of caseless scripts and modifiers letters).
-- This function is equivalent to 'Data.Char.isAlpha'.
isLetter :: Char -> Bool
isLetter c = case generalCategory c of
UppercaseLetter -> True
LowercaseLetter -> True
TitlecaseLetter -> True
ModifierLetter -> True
OtherLetter -> True
_ -> False
And the 定义 http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/GHC-Unicode.html#isAlpha of isAlpha
:
-- | Selects alphabetic Unicode characters (lower-case, upper-case and
-- title-case letters, plus letters of caseless scripts and modifiers letters).
-- This function is equivalent to 'Data.Char.isLetter'.
isAlpha :: Char -> Bool
isAlpha c = iswalpha (fromIntegral (ord c)) /= 0
它们似乎有不同的实现,但据记录它们具有相同的效果。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)