containers: intersections for Set, along with Semigroup newtype

Reed Mullanix reedmullanix at gmail.com
Sun Dec 6 18:41:13 UTC 2020


In a perfect world we would use something like Foldable1 from
semigroupoids, but sadly that is not in base.
However, this is exactly why I proposed the Intersection newtype, as it
would make it nice and easy to use with a Foldable1
like type class.

On Sun, Dec 6, 2020 at 10:27 AM Alexandre Rodrigues Baldé <
alexandreR_B at outlook.com> wrote:

> Sounds like a good idea, could it be possible to use a typeclass instead
> of `NonEmpty (Set a)`?
>
> I recall needing this a few times, but not over a NonEmpty.
>
>
>
> *De:* Libraries <libraries-bounces at haskell.org> em nome de Reed Mullanix <
> reedmullanix at gmail.com>
> *Enviado:* Sunday, December 6, 2020 6:20:02 AM
> *Para:* Haskell Libraries <libraries at haskell.org>
> *Assunto:* containers: intersections for Set, along with Semigroup newtype
>
>
>
> Hey all,
>
> I've found myself reaching for the following function a couple of times
> now, so I figured it might make a good addition.
>
>
>
>   intersections :: Ord a => NonEmpty (Set a) -> Set a
>   intersections (s :| ss) = Foldable.foldl' intersection s ss
>
>
>
> In a similar vein, we may as well add the following newtype + instance
> combo:
>
>
>
>   newtype Intersection a = Intersection { getIntersection :: Set a }
>
>
>
>   instance (Ord a) => Semigroup (Intersection a) where
>       (Intersection a) <> (Intersection b) = Intersection $ intersection a
> b
>       stimes = stimesIdempotent
>
>
>
> Would love to hear everyone's thoughts on this!
>
> Thanks
>
> Reed Mullanix
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20201206/6fc753e3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 77ADE3F8A9834F68A968FAB2DFD72243.png
Type: image/png
Size: 159 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20201206/6fc753e3/attachment.png>


More information about the Libraries mailing list