Skip to content
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

Lhs indexing #609

Merged
merged 9 commits into from
Jun 19, 2019
Merged

Lhs indexing #609

merged 9 commits into from
Jun 19, 2019

Conversation

brianhuffman
Copy link
Contributor

This branch implements the feature requested in #577. It lets us write declarations of the form xs @ i = e, which get desugared as xs = generate (\i -> e).

Before merging, we still need to deal with a problem I introduced in the parser: The changes have introduced a new shift/reduce conflict that I don't yet know how to avoid. We should fix this.

Brian Huffman added 3 commits June 18, 2019 15:39
generate : {n, ix, a}
  (fin ix, n >= 1, ix >= width (n - 1)) => ([ix] -> a) -> [n]a
generate f = [ f i | i <- [0 .. n-1] ]
The declaration `xs @ i = e` is syntactic sugar for
`xs = generate (\i -> e)`.
@brianhuffman brianhuffman requested a review from yav June 18, 2019 23:30
@brianhuffman
Copy link
Contributor Author

Note that this patch does not yet implement lhs indexing for record constructors or field updates. So things like { foo @ i = i+1 } do not work. Should we implement this before merging?

@yav
Copy link
Member

yav commented Jun 19, 2019

It may be nice to to do, if you have the time, just for consistency. You'd have to modify the production for field_expr. Currently we transform a field f x = e into f = \x -> e directly in the parser. We could do the same for indexing where f x @i = e becomes f = \x -> generate (\i -> e).

@yav
Copy link
Member

yav commented Jun 19, 2019

Could you also update docs/Syntax.md with some examples of the new syntax?

For example, we can now write

    foo = { f : [8] -> [4][4][8] }
    foo = { f i @ j @ k = i + j + k }
@brianhuffman
Copy link
Contributor Author

829c9b9 adds support for lhs indexing on record constructors and updates. I still need to update the documentation.

@brianhuffman brianhuffman merged commit 641f656 into master Jun 19, 2019
@brianhuffman brianhuffman deleted the lhs-indexing branch June 19, 2019 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants