This is my first question on this site. So if I am rude or not formal enough, I am sorry already.
In my discrete math class professor showed us this permute function
permute :: [a] -> [[a]]
permute [] = [[]]
permute xs = [y:zs| (y,ys) <- select xs, zs <- permute ys]
select :: [a] -> [(a,[a])]
select [] = []
select (x:xs) = (x,xs) : map(\(y,ys) ->(y,x:ys))(select xs)
I didn't understand this part
permute xs = [y:zs| (y,ys) <- select xs, zs <- permute ys]
I tried permute [1] to understand clearly, in the first recursion select xs takes [1] and returns [(1,[])]. Then permute ys takes [] if I am not mistaken.
In the second recursion, select takes [] and returns [] . I am lost somewhere here. As I see it, it should return [[1],[]] but it returns [[1]].
I would be very happy if someone helps.