-
Notifications
You must be signed in to change notification settings - Fork 57
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
Iterator syntax #2126
Iterator syntax #2126
Conversation
293c0d9
to
4d5a9aa
Compare
e26f8fc
to
e72a670
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- See style #2139 for some style changes
We should have a test that shows the syntax for multiple initializers/ranges.
I propose that the syntax for that follows this schema:
fun (acc1 := a1; .. ; accn := an) (x1 in b1; .. ; xk in bk) body
|
Yes, there is a possibility of ambiguity, I realise this. My proposal is for the iterators to take priority. If one really wants to have a function application with named non-implicit arguments at the beginning, then one can put it in parentheses
This would not be parsed as an iterator because an iterator requires an identifier at the front. This would perhaps be inconvenient if used often, e.g., for the record syntax. But we need something like the |
With a bit more effort in the parser/scoper, one could also recognise when an identifier is an iterator and prioritise iterator syntax only then. But this would require reworking the current iterator parsing concept (to have separate "initializer" and "range" atoms and build (or not) an iterator application only during scoping). |
124b1c9
to
de86305
Compare
de86305
to
d90c862
Compare
A function identifier
fun
can be declared as an iterator withFor example:
Iterator application syntax allows for a finite number of initializers
acc := a
followed by a finite number of rangesx in xs
. For example:The number of initializers plus the number of ranges must be non-zero.
An iterator application
gets desugared to
The
acc1
, ...,accn
,x1
, ...,xk
can be patterns.The desugaring works on a purely syntactic level. Without further restrictions, it is not checked if the number of initializers/ranges matches the type of the identifier. The restrictions on the number of initializers/ranges can be specified in iterator declaration:
The attributes (
init
,range
) in between braces are parsed as YAML to avoid inventing and parsing a new attribute language. Both attributes are optional.