containers: intersections for Set, along with Semigroup newtype

David Feuer david.feuer at gmail.com
Mon Dec 21 15:56:49 UTC 2020


One *could* write

  import Data.Universe.Class (Finite (..))

  class (Ord a, Finite a) => OrderedFinite a where
    orderedFiniteUniverse :: Set a
    orderedFiniteUniverse = S.fromList universeF

  data SMaybe a = SJust !a | SNothing

  wackyIntersections :: OrderedFinite a => [Set a] -> Set a
  wackyIntersections = \ss -> foldr go stop ss SNothing
    where
      stop SNothing = orderedFiniteUniverse
      stop (SJust s) = s

      go s r SNothing = r (SJust s)
      go s r (SJust acc)
        | null acc = empty
        | otherwise = r (SJust acc `intersection` s)

No such things will be going in `containers`, but perhaps they would
fit in `universe`.

On Mon, Dec 21, 2020 at 5:12 AM Tom Ellis
<tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote:
>
> On Sun, Dec 20, 2020 at 11:05:39PM +0100, Ben Franksen wrote:
> > Am 06.12.20 um 19:58 schrieb Sven Panne:
> > > To me it's just the other way around: It violates aesthetics if it doesn't
> > > follow the mathematical definition in all cases, which is why I don't like
> > > NonEmpty here.
> >
> > I think you've got that wrong.
> >
> >   x `elem` intersections []
> > = {definition}
> >   forall xs in []. x `elem` xs
> > = {vacuous forall}
> >   true
> >
> > Any proposition P(x) is true for all x in []. So the mathematical
> > definition of intersections::[Set a]-> Set a would not be the empty set
> > but the set of all x:a, which in general we have no way to construct.
>
> Yes, and to bring this back to Sven's original claim
>
> | 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?
>
> the correct definition of "intersections []" should be "all elements
> which are in all of no sets" i.e. _every_ value of the given type!
>
> Tom
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


More information about the Libraries mailing list