In GHCi entering the following two lines returns a list of lists of two numbers from an input list of numbers such that all combinations are listed, but not using the same element twice.
Prelude> a = [1,3,7,10,25,50]
Prelude> [(x,y) | x <- a, y <- a, x /= y ]
[(1,3),(1,7),(1,10),(1,25),(1,50),(3,1),(3,7),(3,10),(3,25),(3,50),(7,1),(7,3),(7,10),(7,25),(7,50),(10,1),(10,3),(10,7),(10,25),(10,50),(25,1),(25,3),(25,7),(25,10),(25,50),(50,1),(50,3),(50,7),(50,10),(50,25)]
When I write similar code in my .hs program, the compiler keeps rejecting any guard which tests for Equality or Inequality. i.e.
choices :: [a] -> [[a]]
choices [] = [[]]
choices [x] = [[x]]
choices xs = [[m,n] | m <- xs, n <- xs, m /= n ]
The compiler highlights the m /= n. Removing that guard (m =/ n) then the list comprehension works (with duplicate uses of elements of list a) Is this something to do with the compiler not knowing the type of m and n such that it can't assure they are in the type class Ord?