I get an error:
working.hs:186:25: error:
* Couldn't match expected type: Set (Set a)
with actual type: [[a]]
* In the expression:
union (map (insert x) (powerSet s)) (powerSet s)
In an equation for `powerSet':
powerSet (Node x s)
= union (map (insert x) (powerSet s)) (powerSet s)
* Relevant bindings include
s :: Set a (bound at working.hs:186:20)
x :: a (bound at working.hs:186:18)
working.hs:186:48: error:
* Couldn't match expected type: [[a]]
with actual type: Set (Set a)
* In the second argument of `map', namely `(powerSet s)'
In the first argument of `union', namely
`(map (insert x) (powerSet s))'
In the expression: union (map (insert x) (powerSet s)) (powerSet s)
* Relevant bindings include
s :: Set a (bound at working.hs:186:20)
x :: a (bound at working.hs:186:18)
working.hs:186:62: error:
* Couldn't match expected type: [[a]]
with actual type: Set (Set a)
* In the second argument of `union', namely `(powerSet s)'
In the expression: union (map (insert x) (powerSet s)) (powerSet s)
In an equation for `powerSet':
powerSet (Node x s)
= union (map (insert x) (powerSet s)) (powerSet s)
* Relevant bindings include
s :: Set a (bound at working.hs:186:20)
x :: a (bound at working.hs:186:18)
Failed, no modules loaded.
My function is:
powerSet :: Set a -> Set (Set a)
powerSet EmptyS = singleton EmptyS
powerSet (Node x s) = union (map (insert x) (powerSet s)) (powerSet s)
Why do I get the error?
mapis? And what is the type ofinsert?powerSetfunction code looks promising, but you need set versions ofmapand other helper functions for that to work.datadefinition ofSettogether with implementations forunion,insert, etc.?insert :: (Ord a) => a -> Set a -> Set a insert x EmptyS = Node x EmptyS insert x (Node y s) | x == y = Node y s | otherwise = Node y (insert x s)union :: (Ord a) => Set a -> Set a -> Set a union EmptyS s2 = s2 union s1 EmptyS = s1 union s1 s2 = foldr insertSet s1 (toList s2)Otherwise I imported the toList and fromList from Data SetEmptySandNode, where do they come from? They are not inData.Set. Is this your ownSet? You need to post a minimal reproducible example. "Otherwise I imported the toList and fromList from Data Set" If you have your ownSetyou can't do that.