containers: symmetricDifference for Set and HashSet

Andreas Abel andreas.abel at ifi.lmu.de
Tue Dec 1 18:35:14 UTC 2020


 >    symmetricDifference :: Set a -> Set a -> (Set a, Set a, Set a)

Since projections from a 3-tuples are not in base (why?, one could 
wonder), I plea for a telling result name that helps confusing these 
three outputs.  Something like

data SymmetricDifference = SymmetricDifference
   { symDiffLeft   :: Set a
   , symDiffCommon :: Set a
   , symDiffRight  :: Set a
   }

(Also fixing the problem of absent projections.)

On 2020-12-01 10:16, Ben Franksen wrote:
> Would it make sense to add a function like the following to containers:
> 
>    symmetricDifference :: Set a -> Set a -> (Set a, Set a, Set a)
>    symmetricDifference a b = (a \\ b, a `intersection` b, b \\ a)
> 
> with the idea that this can be implemented more efficiently as a
> primitive than the above specification? (And similarly for HashSet.)
> 
> If this is the case, then perhaps difference and intersection could be
> defined in terms of this new primitive:
> 
>    difference a b = let (r, _, _) = symmetricDifference in r
>    intersection a b = let (_, r, _) = symmetricDifference in r
> 
> *if* it turns out that this does not degrade performance.
> 
> Cheers
> Ben
> 
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
> 


More information about the Libraries mailing list