
The powerset of set s is a set containing all subsets of s. I need a clue on how to write Haskell code to get the superset of a set using direct recursion and list comprehension. Best regads.

On Mon, Sep 14, 2015 at 01:57:10PM -0500, JORGE MALDONADO wrote:
The powerset of set s is a set containing all subsets of s. I need a clue on how to write Haskell code to get the superset of a set using direct recursion and list comprehension.
Best regads.
This is good for haskell-beginners rather than haskell cafe. Clue: - say you have a list `l` [a,b,c,d,e] - you have the powerset of list `m` [b,c,d,e] - how can you use the `powerset of m` to calculate the `powerset of l`?

On 2015-09-14 02:57 PM, JORGE MALDONADO wrote:
The powerset of set s is a set containing all subsets of s. I need a clue on how to write Haskell code to get the superset of a set using direct recursion and list comprehension.
"superset"? "subsets"? To compute all subsets of x:xs, i.e., "powerset (x:xs) = ?" : Suppose powerset xs correctly answers you all subsets of xs. How do you build upon its answer to obtain all subsets of x:xs? Basically, each subset of xs is also a subset of x:xs, so you want to include them in your answer for x:xs. On top of that, for each subset of xs, you can insert x and get a subset of x:xs, too. Does this cover all cases?

Le 14/09/2015 20:57, JORGE MALDONADO a écrit :
The powerset of set s is a set containing all subsets of s. I need a clue on how to write Haskell code to get the superset of a set using direct recursion and list comprehension. Clue?...
Three years ago. http://stackoverflow.com/questions/11988184/how-is-this-power-set-generating... Three years ago. http://chaos.weblogs.us/archives/354 etc. Would you mind explaining us, Jorge Maldonaldo, why couldn't you find this by yourself? Is Google so difficult to use? Jerzy Karczmarczuk

On Mon, Sep 14, 2015 at 09:48:41PM +0200, Jerzy Karczmarczuk wrote:
Le 14/09/2015 20:57, JORGE MALDONADO a écrit :
The powerset of set s is a set containing all subsets of s. I need a clue on how to write Haskell code to get the superset of a set using direct recursion and list comprehension. Clue?...
Three years ago.
http://stackoverflow.com/questions/11988184/how-is-this-power-set-generating...
Three years ago.
http://chaos.weblogs.us/archives/354
etc.
Would you mind explaining us, Jorge Maldonaldo, why couldn't you find this by yourself? Is Google so difficult to use?
Clue /= solution. Searching the web tentds to give straight answers rather than hints (which some of us find more useful to progress).

Le 14/09/2015 23:04, Francesco Ariis follows my cold remark suggesting that JM should look upon some sources before asking this list to help to solve his homework:
Clue /= solution. Searching the web tentds to give straight answers rather than hints (which some of us find more useful to progress
? Did *YOU*, Francesco Ariis, verify the references cited? You reproach me of WHAT? The StackOverflow page gives plenty of clues, a little theory, data properties, etc. On the Web you will find what you wish to find. If you don't want hamburger solutions, don't read them. If for you it is more "useful to progress", by querying a community which should be, and IS helpful, but will not replace your ELEMENTARY textbooks, and your teachers, I don't think we share the same vocabulary. Jerzy Karczmarczuk

Jerzy, you have been on this list long enough to know that is not an appropriate tone to use when responding to people asking questions. I am not disagreeing with the *content* of your message --- indeed, the original message sounded a lot like asking the list to solve a homework problem. But your response seemed unnecessarily sarcastic and condescending. -Brent On Mon, Sep 14, 2015 at 2:49 PM Jerzy Karczmarczuk < jerzy.karczmarczuk@unicaen.fr> wrote:
Le 14/09/2015 20:57, JORGE MALDONADO a écrit :
The powerset of set s is a set containing all subsets of s. I need a clue on how to write Haskell code to get the superset of a set using direct recursion and list comprehension. Clue?...
Three years ago.
http://stackoverflow.com/questions/11988184/how-is-this-power-set-generating...
Three years ago.
http://chaos.weblogs.us/archives/354
etc.
Would you mind explaining us, Jorge Maldonaldo, why couldn't you find this by yourself? Is Google so difficult to use?
Jerzy Karczmarczuk
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Le 14/09/2015 23:45, Brent Yorgey a écrit :
you have been on this list long enough to know that is not an appropriate tone to use when responding to people asking questions. /.../ your response seemed unnecessarily sarcastic and condescending.
I am sorry. It was not my purpose to offend anybody, *sincerely*. If I might have been understood in such a way, I apologize. But, Brent, please : there was no question to answer. Jorge M. said: "I need a clue...". I gave him, indirectly. I responded thus after having read the answers by Albert Lai, OK, but short, probably worth completing, and the second one, by Francesco Ariis, which was not a clue at all, it simply said "use recursion", while Jorge Maldonado explicitly said that he would use recursion... +. Jerzy

On Tue, Sep 15, 2015 at 4:45 AM, Brent Yorgey
Jerzy, you have been on this list long enough to know that is not an appropriate tone to use when responding to people asking questions. I am not disagreeing with the *content* of your message --- indeed, the original message sounded a lot like asking the list to solve a homework problem. But your response seemed unnecessarily sarcastic and condescending.
Wait, Brent, surely you're referring to Jerzy's 2nd email? The first one to Jorge is a gallicism of lmgtfy. The second one to Francesco is when he has worked himself up to into a mousse. (Francesco must've been bemused!) All very thrilling. And for only powerset. Imagine the crackling energies before rawer topics. -- Kim-Ee

On 15/09/2015, at 6:57 am, JORGE MALDONADO
The powerset of set s is a set containing all subsets of s. I need a clue on how to write Haskell code to get the superset of a set using direct recursion and list comprehension.
Here is a clue.
The question is not well posed.
What is the representation of sets going into your function? What is the representation of sets coming out of your function? You could, for example, perform the operation in constant time by playing games with representations: given a representation of a set, return a wrapper containing that represent typeclass Eq t => Set t where is_element :: t -> Set t -> Bool instance Eq t => Set [t] where is_element = elem newtype Power t = Power t instance Set t => Set (Power t) where is_element x (Power s) = is_subset x s (Very rough sketch done in haste.) We can throw in a direct recursion (in the definition of is_subset, perhaps) and a list comprehension if you like. I am not suggesting that you *should* do this, but that your problem as stated *does not rule this out* as (the beginnings of) an answer. So start by spelling out what you are going to use to represent a set and *how* one of those represents the set it does. Then think about the calculation you want to do *in terms of sets*, not your representation. P {} = {{}} P ({x} U s) = something involving x, s, and P s. You also need to be clear about what it is that you are doing. Are you building some code that you expect to use in a real program? In that case, what is this going to cost you? (Hint: if |s| = n, what is |P s|?) If you are doing homework, what is going to get you marks? Surely, it is demonstrating understanding. In this case, yo seem to be asked to show that you understand recursion, and list comprehensions. The (incomplete) definition of the power set of a finite set given above (P) is naturally recursive. What makes it a good recursion is that the cases are clearly distinct and the recursive call (P s) has an argument that is strictly smaller than what you started with ({x} U s) provided of course that x is not an element of s. What makes it a questionable definition is that it seems to depend on which x we pick. But does it? You need to *argue* that P({}) = {{}} P({x} U s) = something involving x, s, and P(s) for *any* partition of a non-empty set n into {x} and s = n\{x}. Then your code can pick whatever x is easiest to find in the data structure you're using to represent a set. Final thought. If p1 [1,2] = [[],[1],[2],[1,2]] and p2 [1,2] = [[2,1],[2],[1],[]] are they *both* good answers, or neither, or just one?
participants (7)
-
Albert Y. C. Lai
-
Brent Yorgey
-
Francesco Ariis
-
Jerzy Karczmarczuk
-
JORGE MALDONADO
-
Kim-Ee Yeoh
-
Richard A. O'Keefe