1

I have searched and found some solutions but none of them look as simple as what i have in mind, so you have a list of numbers [1,2,3,4] and want to print the tuples like this: [(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)]

So by using

combinaList :: String -> String
combinaList x = [(x,y) | x <- x, y <- drop 1 x ]

Should do the trick, drop the first element from the list and combine the two lists, however I am getting my types wrong and possibly the drop bit too as ghci keeps on whinning at me, any help would be appreciated, thanks!

4

1 回答 1

6

Use tails from Data.List.

combinaList xs = [(x, y) | (x:ys) <- tails xs, y <- ys]
于 2013-03-29T22:03:17.440 回答