isAlpha和isLetter有什么区别? [英] What is the difference between isAlpha and isLetter?

查看:1044
本文介绍了isAlpha和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?

推荐答案

查看资源,它们似乎是等同的。

Looking at the sources they appear to be equivalent.

以下是4.3.1.0中定义的 isLetter 的定义

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

并且定义 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.

这篇关于isAlpha和isLetter有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆