Write a Haskell function compareChars Char Char Char Str
Write a Haskell function
compareChars :: Char -> Char -> Char -> String such that (compareChars a b c) returns a string indicating how many of the characters a, b, c are equal to one another:
If all three are the same, it returns \"All equal\".
• If exactly two of them are the same, it returns \"Two match\".
• If all three are different, it returns \"All distinct\".
For example, (compareChars ’R’ (toUpper ’r’) ’R’) returns \"All equal\", (compareChars ’R’ ’r’ ’R’) returns \"Two match\", and (compareChars ’a’ ’B’ ’b’) returns \"All distinct\".
The function is look like this (but this is wrong )
compareChars :: Char -> Char -> Char -> String
compareChars a b c
| (compareChars \'R\' (toUpper\'r\')\'R\') == \"All equal\"
| (compareChars \'R\' \'r\' \'R\') == \"Two match\"
| (compareChars \'a\' \'B\' \'b\') == \"ALL distinct\"
Solution
compareChars :: Char -> Char -> Char -> String
compareChars a b c | (compareChars \'a\' \'b\' \'c\') == \"all equal\"
| (compareChars (\'a\' \'A\' \'a\')(\'b\' \'B\' \'b\') (\'c\' \'C\' \'c\')) == \"Two Match Found\"
| (compareChars (\'a\' \'A\' \'b\' \'B\' \'c\' \'C\') == \"All distinct\"
countLetters :: Char -> Char -> Int
countLetters Char a b c = length $ filter (== a b c) char
