I am new to Haskell. I have string containing single character for example "A" or "3". I want to turn it into character to check if it is a digit with isDigit :: Char -> Bool function. How can I turn that the string into character?
I tried:
isDigit head x
-- and
isDigit take 1 x
witch gave me errors:
Variable not in scope: isDigit :: ([a0] -> a0) -> String -> Bool and Variable not in scope: isDigit :: (Int -> [a0] -> [a0]) -> t0 -> String -> Bool
isDigit head xcallsisDigitwith two arguments (headandx). You probably wantisDigit (head x)instead. The expressionisDigit take 1 xsuffers from the same issue (but won't work anyway, sincetakereturns a list/string, not a single char).all isDigitto be robust to mistakenly calling with strings of other lengths. Or, if this is part of a validation pass, something likesingleDigit :: String -> Maybe Int; singleDigit [x] | isDigit x = Just (digitToInt x); singleDigit _ = Nothing, which returns a failed validation for other lengths, and converts to a more suitable internal representation when validation passes.