containers: intersections for Set, along with Semigroup newtype

Reed Mullanix reedmullanix at gmail.com
Sun Dec 6 18:55:59 UTC 2020


It doesn't violate any laws per say, due to the general lawlessness of
Foldable, but violates aesthetics. If we restrict it to NonEmpty then we
get a lovely semigroup homomorphism!
If we loosen it to lists, then the identity element of the list monoid gets
mapped to an absorbing element in the Set semigroup under intersection,
which just feels... off.

On Sun, Dec 6, 2020 at 10:50 AM Sven Panne <svenpanne at gmail.com> wrote:

> Am So., 6. Dez. 2020 um 07:20 Uhr schrieb Reed Mullanix <
> reedmullanix at gmail.com>:
>
>> [...]
>>   intersections :: Ord a => NonEmpty (Set a) -> Set a
>>   intersections (s :| ss) = Foldable.foldl' intersection s ss
>> [...]
>>
>
> Why NonEmpty? I would expect "intersections [] = Set.empty", because the
> result contains all the elements which are in all sets, i.e. none. That's
> at least my intuition, is there some law which this would violate?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20201206/afd4178f/attachment.html>


More information about the Libraries mailing list