I looked at Data.Set and I found out that it does not have powerset function. Why?
I can implement it as follows:
import Data.Set (Set, empty, fromList, toList, insert) powerset :: (Ord a) => Set a -> Set (Set a) powerset s = fromList $ map (fromList) (powerList $ toList s) powerList :: [a] -> [[a]] powerList [] = [[]] powerList (x:xs) = powerList xs ++ map (x:) (powerList xs)
But this is not the most effective way to do this. Ok i can also write
powerList :: [a] -> [[a]] powerList = filterM (const [True, False])
but still, I wonder why Data.Set does not have a powerset function.
Also, what is the best way to write powerset :: (Ord a) => Set a -> Set (Set a) ?
MarcoS
source share