I need to split a list into a list of all possible tuples, but I\'m unsure of how to do so.
For example:
pairs [\"cat\",\"dog\",\"mouse\"]
Another possibility is to use monadic notation:
pairs :: (Eq a) => [a] -> [(a,a)]
pairs l = do
x <- l
y <- l
guard (x /= y)
return (x, y)
(The most general type for this definition of pairs
would be (MonadPlus m, Eq a) => m a -> m (a,a)
but I believe there is no instance of MonadPlus
other than []
for which it would make sense.)