Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between isAlpha and isLetter?

Tags:

char

haskell

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?

like image 326
Amit Avatar asked Nov 21 '12 20:11

Amit


Video Answer


2 Answers

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.

like image 138
nixeagle Avatar answered Sep 20 '22 12:09

nixeagle


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.

like image 22
mipadi Avatar answered Sep 16 '22 12:09

mipadi