I have the following question (Haskell - The Craft of Functional Programming):
Give a definition of the function
howManyEqua1 :: Int -> Int -> Int -> Int
which returns how many of its three arguments are equal, so that
howManyEqua1 :: 34 25 36 = 0
howManyEqual :: 34 25 34 = 2
howManyEqual :: 34 34 34 = 3
The answer I gave is:
howManyEqual :: Int -> Int -> Int -> Int
howManyEqual a b c
| a == b && b == c = 3
| a == b = 2
| b == c = 2
| a == c = 2
| otherwise = 0
However, I believe there is a better way to classify it but am not sure of how.
How about:
howManyEqual a b c
| a == b && b == c = 3
| a /= b && a /= c && b /= c = 0
| otherwise = 2
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