Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Haskell function compareChars :: Char -> Char -> Char -> String such tha

ID: 3785396 • Letter: W

Question

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"

Explanation / Answer

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote