Created
September 4, 2015 04:24
-
-
Save LOZORD/94da315953fb98fc9ba8 to your computer and use it in GitHub Desktop.
Powerset implementation in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import qualified Data.Set as Set | |
| phi :: Set.Set a | |
| phi = Set.empty | |
| pset :: (Ord a) => Set.Set a -> Set.Set (Set.Set a) | |
| pset set = if (Set.null set) | |
| then Set.singleton phi | |
| else | |
| let head = Set.elemAt 0 set | |
| headSet = Set.singleton head | |
| headUnion = \lilsubset -> lilsubset `Set.union` headSet | |
| rest = Set.deleteAt 0 set | |
| subsets = pset rest -- recursive call | |
| in subsets `Set.union` (Set.map headUnion subsets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment