-
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
New syntax for function definitions #2243
Conversation
68deb57
to
8531b22
Compare
8531b22
to
dc05562
Compare
a61ad4f
to
b528052
Compare
2c84e1d
to
595662a
Compare
In https://github.com/anoma/juvix-stdlib/blob/85751d3a7e5edd97a3d12dae197273731a2088cf/Stdlib/Data/Bool.juvix#L15 we now must write:
instead of:
(The latter now fails the termination checker). The reasoning for allowing |
If implementors of traits must use
Then implementors of traits would not have to do any additional imports other than the Prelude (as before) and could write the following (avoiding the stuttering):
What do you think? |
This was a side-effect of allowing forward references. Before the |
I agree that One option is to replace the existing
By
And then have
As you suggested. |
The main issue I have with the |
That's true, but this is a temporary problem. In the not so distant future we will have trait instances, which will not bind any name, and so this won't be a problem anymore. So trait implementors (outside of the stdlib) will be able to write
In the meanwhile, another possible temporary patch would be to add a local module in the prelude:
And then the users can write:
It is maybe slightly better than the option I gave before, but it still does not fully solve the discoverability problem |
This is very good - thanks! I'll raise it as an issue against stdlib once this PR is merged. |
Closes Syntax for mutually recursive types #2060
Closes Re-think function definitions #2189
This pr adds support for the syntax described in Re-think function definitions #2189. It does not drop support for the old syntax.
It is possible to automatically translate juvix files to the new syntax by using the formatter with the
--new-function-syntax
flag. E.g.Syntax changes
Type signatures follow this pattern:
where each
ai
is a non-empty list of symbols. Braces are used instead of parentheses when the argument is implicit.Then, we have these variants:
:= Expr;
.Mutual recursion
Now identifiers do not need to be defined before they are used, making it possible to define mutually recursive functions/types without any special syntax.
There are some exceptions to this. We cannot forward reference a symbol
f
in some statements
if betweens
and the definition off
there is one of the following statements:I think it should be possible to drop the restriction for local modules and import statements