2012-11-21 25 views
8

在Haskell中,函數Data.Char.isAlpha檢查一個字符是否是字母,但Data.Char.isLetter也是如此。這些功能之間有沒有真正的區別,還是可以互換?isAlpha和isLetter有什麼區別?

回答

8

看着sources他們似乎是相同的。

這裏是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 

規定和definition​​的:

-- | 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 

他們似乎有不同的實現,但它們都記錄有同樣的效果。

6

現在沒有真正的區別。從the docs

isAlpha :: Char -> Bool
選擇字母Unicode字符(小寫,大寫和標題大小寫字母,再加上無殼腳本和修飾符字母的字母)。該功能等同於Data.Char.isLetter。