<div dir="ltr">Naïvely, a set implemented as a predicate determining membership?</div><br><div class="gmail_quote"><div dir="ltr">On Sun, Dec 9, 2018 at 1:32 PM Siddharth Bhat <<a href="mailto:siddu.druid@gmail.com">siddu.druid@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I don't understand, how does <div><br></div><div>(a -> Bool) -> a</div><div><br></div><div>model a set?</div><div><br></div><div>Thanks</div><div>Siddharth</div><div><br><div class="gmail_quote"><div dir="ltr">On Sun, 9 Dec, 2018, 22:08 Olaf Klinke, <<a href="mailto:olf@aatal-apotheke.de" target="_blank">olf@aatal-apotheke.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> Note that a concrete set "concretizes" anything it touches.  Don't take<br>
> unions of these sets, though, it'll just be a mess.<br>
> <br>
> <br>
> Won't a union just be the same as intersection but using || instead of && ?<br>
> <br>
> <br>
> -Jan-Willem Maessen<br>
<br>
Unions of predicates and concrete sets are easy, thanks to Set.member:<br>
<br>
union (Pred p) (Concrete s) = Pred (\k -> p k || member k s)<br>
<br>
What you can not do, of course, is enumerate and fold these sets. <br>
There is a set type [1] which supports a litte bit more: <br>
<br>
Set a = Maybe ((a -> Bool) -> a)<br>
<br>
It has unions, intersections and a Monad instance and can represent infinite sets. If the base type has an Ord instance, the set can be enumerated. If the base type has an Eq instance, so has (Set a). Some functions usually implemented using Foldable are also possible, e.g. minimum and maximum. <br>
Caveat: Performance can be poor, depending on how the function inside the set was defined. <br>
<br>
Cheers,<br>
Olaf<br>
<br>
[1] <a href="http://hackage.haskell.org/package/infinite-search" rel="noreferrer" target="_blank">http://hackage.haskell.org/package/infinite-search</a><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div></div>-- <br><div dir="ltr" class="gmail-m_5615470411049631379gmail_signature"><div dir="ltr">Sending this from my phone, please excuse any typos!</div></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>brandon s allbery kf8nh</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a></div></div></div></div></div>