[Haskell-cafe] testing for same characters in lists of strings

Stuart Cook scook0 at gmail.com
Mon Apr 7 23:33:28 EDT 2008

On Tue, Apr 8, 2008 at 1:51 PM, Jackm139 <jackmarathon at gmail.com> wrote:
>  I have an assignment to make a program to test whether two lists use the
>  same characters for each string.
>  e.g.
>  sameCharacter ["rock", "cab"] ["cork", "abc"]
>  True

I would start with something smaller: try defining a function that
will check if two *strings* use the same characters. It would look
something like this:

  same :: String -> String -> Bool
  same xs ys = normalize xs == normalize ys

  normalize :: String -> String
  normalize xs = error "insert your implementation here"

Define the "normalize" function so that it does whatever is necessary
to make two strings with the same characters into the same string
(using nub, sort, and/or whatever else is appropriate).

Once you have the "same" function working, you can use it to define
"sameCharacter". You might want to take a look at the functions "zip",
"zipWith", "all", and "and", which can be found in the Prelude.

Hopefully this will help you get started.


More information about the Haskell-Cafe mailing list