From http://www.meetup.com/hoodlums/events/91349692/
Define a function cat
that takes an arbitrary number of strings and returns the concatenation of all strings. You'll need the FlexibleInstances
extension (but should not need any others). When calling in GHCi, you will have to annotate the result type of the function. Examples:
> cat :: String
""
> cat "foo" "bar" :: String
"foobar"
> cat "Haskell" "Hoodlums" "Meetup" :: String
"HaskellHoodlumnsMeetup"
If you like a follow-up exercise, then modify the function into a function count that takes an arbitrary number of String or Integer arguments and computes an Integer that is the sum of all the given integers plus the sum of the lengths of all strings. Examples:
> count :: Integer
0
> count "foo" (7 :: Integer) "bar" :: Integer
13
You can also try to get rid of the Integer type annotation on the argument.