I'm new to haskell and was trying to write a function to generate a powerset which only includes consecutive subsets eg: [1,2,3] -> [[],[1],[2],[3],[1,2],[2,3],[1,2,3]]
I found this on a blog http://davidtran.doublegifts.com/blog/?p=7
powerset :: [a] -> [[a]]
powerset [] = [[]]
powerset (x:xs) = powerset xs ++ map (x:) (powerset xs)
-- powerset (x:xs) = powerset xs ++ [x:xs' | xs' <- powerset xs]
but this generates all the subsets i.e [1,3] included which i dont want? is there anyway to fix this code to work or do I have to rethink my approach. Also i do not want to use built in library functions, wanna get my basics right.