How to work with 2 lists at the same time in haskell

Viewed 754

I'm trying to solve an exercise in haskell about alphabets. Given a list of words in a new alphabetical order, find this new alphabet.

For example, given the words ["ab","abd","abc","ba","bd","cc"], the new possible alphabets are "abdc" or "adbc".

I started by computing all possible alphabetical orders

alfabet :: Eq a => [[a]] -> [[a]]
alfabet list = permutations $ nub $ concat $ list

After this, I think I should filter out those alphabets that are wrong, but I can't seem to pass along enough info. I've tried using the built-in filter function, I've tried to write my own sort function so that when I sort the words by the new order, the resulting list is the same as the input list thus the alphabet is correct. All to no avail.

I guess the biggest problem I have is that I need to be able to work with two lists (the words and the different alphabets) at the same time and loop over them in a different way.

Any tips or help? Thanks

2 Answers
Related