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

Add default arguments #2408

Merged
merged 34 commits into from
Oct 10, 2023
Merged

Add default arguments #2408

merged 34 commits into from
Oct 10, 2023

Conversation

janmasrovira
Copy link
Collaborator

@janmasrovira janmasrovira commented Sep 28, 2023

This PR implements default arguments as described in #2386.

Change list

  1. Extension of concrete syntax to include default values in function definitions.
  2. Generalization of NameSignature/Builder so that it can also be used with scoped syntax.
  3. Adaptation of Internal.FromConcrete.NamedArguments so that we insert default values instead of holes when needed.
  4. Adaptation of ArityChecking.Checker so that it inserts default values instead of holes when needed.

Limitations

  1. default values cannot refer to previous arguments. E.g., the following is a scope error:
    f {n : Nat := 0} {m : Nat := n + 1} .... 
    
  2. Only functions can have default values.
  3. Ony arguments on the LHS of the : can have arguments. E.g., the following is not valid syntax:
    f : {n : Nat := 0} := ...
    
    This is probably what we want since we want default arguments to be associated with the name of a function rather than a type.

@janmasrovira janmasrovira added enhancement New feature or request syntax labels Sep 28, 2023
@janmasrovira janmasrovira added this to the 0.5.2 milestone Sep 28, 2023
@janmasrovira janmasrovira self-assigned this Sep 28, 2023
@janmasrovira janmasrovira linked an issue Sep 28, 2023 that may be closed by this pull request
@janmasrovira janmasrovira force-pushed the 2386-default-values-for-arguments branch from 7c4ea5d to b64a388 Compare September 29, 2023 16:31
@janmasrovira janmasrovira force-pushed the 2386-default-values-for-arguments branch from b64a388 to e5edbf6 Compare September 30, 2023 23:23
@janmasrovira janmasrovira force-pushed the 2386-default-values-for-arguments branch from ed55fa7 to 5e40cd2 Compare October 2, 2023 15:24
@jonaprieto jonaprieto modified the milestones: 0.5.2, 0.5.3 Oct 2, 2023
@janmasrovira janmasrovira marked this pull request as ready for review October 5, 2023 15:00
@paulcadman
Copy link
Collaborator

It looks like there's some issue with type checking the default values?

The following type checks:

type T := mkT;
type U := mkU;

g {a : T := mkU} : T := a;

@janmasrovira
Copy link
Collaborator Author

janmasrovira commented Oct 6, 2023

It looks like there's some issue with type checking the default values?

The following type checks:

type T := mkT;
type U := mkU;

g {a : T := mkU} : T := a;

Oops. Because g is not used the default value is never inserted and so it does not reach type checking.
Maybe we'll need to keep default values in the Internal language so we can check them

@janmasrovira
Copy link
Collaborator Author

@paulcadman now default values are typed checked even if they are not used. I've added a negative test for it.

@janmasrovira janmasrovira merged commit a5516a5 into main Oct 10, 2023
4 checks passed
@janmasrovira janmasrovira deleted the 2386-default-values-for-arguments branch October 10, 2023 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request syntax
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default values for arguments
3 participants