isAlpha和isLetter有什么区别?(What is the difference between isAlpha and isLetter?)

编程入门 行业动态 更新时间:2024-10-27 03:28:25
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 _ -> False

And 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)) /= 0

They appear to have different implementations, but they are documented to have the same effect.

更多推荐

本文发布于:2023-07-30 12:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1337887.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   isAlpha   isLetter   difference

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!