-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: combine set filter and set map language constructs #10
Comments
I agree that the combined syntax would be convenient, and it has been used since Dijkstra. For constructs involving multiple bound variables, an arguably more readable translation (even after your edit) is
|
I don't love the second colon in The { f(x) : x \in S /\ p(x) } Thoughts? |
We've received numerous complaints from our target audience about the difficulty and confusion surrounding TLA+ syntax. I suggest we explore ways to assess whether these language extensions are beneficial or detrimental to addressing this issue. To that end, extensions could be required to come with a desugaring tool. |
@lemmy to my mind this is a simplification of syntax. Users are well-acquainted with map/filter from many other languages, like Python or SQL. The current way of filtering then mapping is very verbose, confusing to read, and confusing to write. I would go as far as to say map and filter should be treated as specialized forms of this operation instead of this operation desugaring to map and filter. @Calvin-L don't really like the use of |
Might very well be, but let's be data-driven: What's the background of the average target user? What do existing and potential users find confusing? How important is writability compared to readability? There is no need to rush here, and these RFCs should seek input from a broad group of users, not just four or five experts. Related: #1 Personally, I'm not against this proposal. |
@hwayne provides the interesting suggestion that as part of these changes, set filter with multiple quantifier bounds could also be added to the language; |
What about comma? That would align with current TLA+ syntax, where bounds are comma-separated.
That's a good point. Should we be surveying how other languages handle set comprehensions? For instance, Haskell allows a comma-separated list of clauses where you can mix binders and filters: let catsInGoodHomes = [c | h <- homes, isGood h, c <- cats h] You can even put let-bindings in the clauses; Python has similar syntax: catsInGoodHomes = [c for h in homes if isGood(h) for c in cats(h)] These are some examples of how that might be written in TLA+:
On a related note, even though TLA+ does allow multiple bounds in set-filter expressions, it does not allow the bound a variable to depend on another. The TLA+ version of my example is not legal, even without a filter clause: catsInGoodHomes == {c : h \in homes, c \in cats(h)}
\* ^^^^^^^ I often want that feature. |
The issue with commas is then it becomes difficult to tell whether you are entering another bound quantifier or entering the predicate. Given that |
The problem I always have with teaching TLA+ is that students can never
remember which is map and which is filter. I worry that will be even harder
if mapfilter used two colons. Off the wall idea, but what about `{f(x): x
\in Set WHERE p(x)}`?
Also more generally, how much space is there for modifying tla syntax? Is
this the only change being considered or are we thinking of adding more
syntactic sugar in general?
…On Fri, May 17, 2024, 6:39 PM Andrew Helwer ***@***.***> wrote:
The issue with commas is then it becomes difficult to tell whether you are
entering another bound quantifier or entering the predicate. Given that {
x \in S : p(x) } is already the syntax when filtering, don't you think it
makes sense to keep it?
—
Reply to this email directly, view it on GitHub
<#10 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAUJO5HVSSC4IGC4NSCOCN3ZC2IL5AVCNFSM6AAAAABHN24X6GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJYGQ4TIOJSGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I like Hillel's idea. It would be interesting to use optional keywords instead of |
I often find myself wanting to both filter and map a set. The way to do this in TLA+ is currently:
or
I think it would be nicer to make this a single operation:
One possible semantic issue is that set mapping supports multiple quantifier bounds:
while set filtering only supports a single quantifier:
because after all, what would
{ x \in S, y \in P : p(x, y) }
even mean?Fortunately having a map operation ensures that these bounds will coalesce into a single stream of elements. However, it does make things more difficult when trying to define the semantics of this combined map/filter operation, since you can't easily decompose it into a set map then a set filter. What does this mean, for example?
It cannot be easily written in terms of the existing map and filter constructs. I believe the translation would have to be something like this:
So it would be a map that wraps the multiple quantifier bounds in a tuple, nested inside the filter that recovers their names with a tuple destructuring, nested inside the map that recovers their names using tuple destructuring.
The text was updated successfully, but these errors were encountered: