From: Mart Lubbers Date: Tue, 3 Mar 2015 11:37:56 +0000 (+0100) Subject: mooiere powerset X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=d21ead92c20299ce914b1e3a7663990f9a3e85f1;p=fp1415.git mooiere powerset --- diff --git a/week4/mart/StdSet.dcl b/week4/mart/StdSet.dcl index 6cad7f1..0c702ca 100644 --- a/week4/mart/StdSet.dcl +++ b/week4/mart/StdSet.dcl @@ -22,4 +22,4 @@ product :: (Set a) (Set b) -> Set (a,b) instance zero (Set a) instance == (Set a) | Eq a -powerSet :: (Set a) -> Set (Set a) +powerSet :: (Set a) -> Set (Set a) | Eq a diff --git a/week4/mart/StdSet.icl b/week4/mart/StdSet.icl index a14e6ba..ecb2e60 100644 --- a/week4/mart/StdSet.icl +++ b/week4/mart/StdSet.icl @@ -48,9 +48,7 @@ where zero = Set [] instance == (Set a) | Eq a where (==) s1 s2 = isSubset s1 s2 && isSubset s2 s1 -powerSet :: (Set a) -> Set (Set a) -powerSet (Set a) = Set [(Set x) \\ x <- powerSet2 a] -where - powerSet2 :: [a] -> [[a]] - powerSet2 [] = [[]] - powerSet2 [e:xs] = (powerSet2 xs) ++ [[e:x] \\ x <- powerSet2 xs] +powerSet :: (Set a) -> Set (Set a) | Eq a +powerSet (Set []) = Set [(Set [])] +powerSet (Set [e:xs]) = union (powerSet (Set xs)) + (Set [union (Set [e]) x \\ x <- fromSet (powerSet (Set xs))])