haskell - Sublists of a list using list comprehension -
that simple. want generate sublists of list using list comprehension.
i.e: getsublist [1,2,3] [[1], [2], [3], [1,2], [1,3], [2, 3], [1,2,3]]
thanks
this implemented data.list.subsequences, if want define (for learning purposes), can this:
you can't list comprehensions, recursion looks this:
sublists [] = [[]] sublists (x:xs) = [x:sublist | sublist <- sublists xs] ++ sublists xs read: sublist of empty list empty list. sublists of x:xs (i.e. list head x , tail xs) of sublists of xs each of sublists of xs x prepended them.
Comments
Post a Comment