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.
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.
There's no real difference now. From the docs:
isAlpha :: Char -> Bool
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With