lexPerms [] = [[]] lexPerms l = concatMap (\(x,y) -> map (x:) $ lexPerms y) $ cp [] l where cp p (x:xs) = (x,p++xs) : cp (p++[x]) xs cp p _ = []