From the conclusion that both programs compute the same result it can be concluded that the fact that you have made use of a list comprehension has forced you to make a choice which should not matter, i.e. the order in which to place the generators. This should be apparent from your code.My approach is such a situation is to "define your own generator" (assuming here that isSafe needs both its parameters):pl `x` ql = [ (p,q) | p <-pl, q <- ql]queens3 n = map reverse $ queens' nwhere queens' 0 = [[]]queens' k = [q:qs | (qs, q) <- queens' (k-1) `x` [1..n], isSafe q qs]isSafe try qs = not (try `elem` qs || sameDiag try qs)sameDiag try qs = any (\(colDist,q) -> abs (try - q) == colDist) $ zip [1..] qsOf course you can make more refined versions of `x`, which perform all kinds of fair enumeration, but that is not the main point here. It is the fact that the parameters to `x` are only evaluated once which matters here.