Function2.hs: 3-tuple exercise cannot be solved without pattern matching
functional-fox opened this issue · comments
Hello and thank you for creating haskellings! I'm not completely new to Haskell, but I'm looking to brush up on my skills and haskellings seem like an excellent opportunity to do this.
In Function2.hs
, there is the following exercise:
-- Capitalize each of the three characters
capitalize :: (Char, Char, Char) -> (Char, Char, Char)
capitalize = ???
However, this exercise cannot be solved with the fst
and snd
functions mentioned further above in the file since they only work on tuples of two elements, not three. I solved the exercise using pattern matching, but pattern matching has not been introduced yet, so this is not ideal:
-- Capitalize each of the three characters
capitalize :: (Char, Char, Char) -> (Char, Char, Char)
capitalize (a,b,c) = ((toUpper a), (toUpper b), (toUpper c))
If the use of fst
and snd
is to be taught here, this is what the exercise should look like in my opinion:
capitalizeFixed :: (Char, Char) -> (Char, Char)
capitalizeFixed tuple = ((toUpper (fst tuple)), (toUpper (snd tuple)))
Test case to be added:
, testCase "capitalizeFixed" $ capitalizeFixed ('z', 'k') @?= ('Z', 'K')
Good call out! I'll take a look at this next week unless someone else gets a PR up first.
Pull request #36 is up 🙂