title: Representing set-theoretical notions in terms of lists in Haskell
body: <p>I'm trying to define a new type in Haskell (i.e. sets) and to operate with it in terms of functions that input and output unordered lists without duplicates.</p>
  
  <p>Am I on the right path over here? Any suggestion is welcomed, even the most minor quibble. I'd want my code to be as elegant as possible.</p>
  
  <pre><code>-- generalized membership
  
  type Set a = [a]
  
  member :: Eq a =&gt; a -&gt; [a] -&gt; Bool
  member x []                 = False
  member x (y:ys) | x == y    = True
                  | otherwise = member x ys                
  
  -- elimination of duplicates
  
  noReps :: Set Integer -&gt; Set Integer
  noReps []                   = []
  noReps (x:xs) | member x xs = noReps xs
                | otherwise   = x : noReps xs
  
  inclusion :: Set Integer -&gt; Set Integer -&gt; Bool
  inclusion x y = length [i | i &lt;- x, not (member i y)] == 0
  
  identical :: Set Integer -&gt; Set Integer -&gt; Bool 
  identical x y = inclusion x y &amp;&amp; inclusion y x
  
  -- membership for sets of sets
  
  setmember :: Set Integer -&gt; Set (Set Integer) -&gt; Bool
  setmember [] _                      = True
  setmember _ []                      = False
  setmember x (y:ys)  | identical x y = True 
                      | otherwise     = setmember x ys   
  
  addsets :: Set Integer -&gt; Set (Set Integer) -&gt; Set (Set Integer)
  addsets x y | setmember x y = y
              | otherwise = x:y
  
  -- adding an integer to every member of a sets of sets of integers
  
  addelem :: Integer -&gt; Set (Set Integer) -&gt; Set (Set Integer) 
  addelem x y = [noReps (x : i) | i &lt;- y]
  
  -- powerset of the set {1,...,n}
  
  powerset :: Integer -&gt; Set (Set Integer)
  powerset 1 = [[], [1]]
  powerset x = powerset (x-1) ++ addelem x (powerset (x-1))
  </code></pre>