isAlpha和isLetter有什么区别?(What is the difference between isAlpha and isLetter?)
在Haskell中,函数Data.Char.isAlpha检查一个字符是否是字母,但Data.Char.isLetter也是如此。 这些功能之间有没有真正的区别,还是可以互换?
In Haskell, the function Data.Char.isAlpha checks if a character is a letter, but so does Data.Char.isLetter. Is there any real difference between these functions, or are they interchangeable?
最满意答案
看他们似乎是相同的来源 。
这是isLetter中定义的isLetter的定义
-- 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而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他们似乎有不同的实现,但它们被记录为具有相同的效果。
Looking at the sources they appear to be equivalent.
Here is the definition of isLetter as defined in 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 _ -> FalseAnd the definition 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)) /= 0They appear to have different implementations, but they are documented to have the same effect.
更多推荐
发布评论