import Control.SetFunctions -- Permutation of a list: perm :: [a] -> [a] perm [] = [] perm (x:xs) = insert (perm xs) where insert ys = x : ys insert (y:ys) = y : insert ys -- An unsafe permutation: unsafe :: [Int] -> Bool unsafe xs | xs =:= _ ++ [i] ++ zs ++ [j] ++ _ = abs (i - j) =:= length zs + 1 where i,j,zs free -- Solution to the n queens problem: -- Here: weak encapsulation via set function is important!!! queens :: Int -> [Int] queens n | isEmpty ((set1 unsafe) p) = p where p = perm [1..n]