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

Allow default values to refer to previous arguments #2445

Closed
janmasrovira opened this issue Oct 16, 2023 · 0 comments · Fixed by #2446
Closed

Allow default values to refer to previous arguments #2445

janmasrovira opened this issue Oct 16, 2023 · 0 comments · Fixed by #2446
Assignees
Labels
enhancement New feature or request pending-review
Milestone

Comments

@janmasrovira
Copy link
Collaborator

e- Currently default values can only refer to names available at the top scope (i.e. the scope where the function/constructor being defined is).
Sometimes it can be useful to refer to previos arguments. For instance consider the example given in #2427:

trait
type Ord A := mkOrd {
  cmp : A -> A -> Ordering
  < (x y : A) : Bool := case cmp x y of {
    | LT := true
    | _ := false
  };
  ..
};

In the default definition of < we need to refer to cmp.

Implementation

We briefly discussed online one possible way to implement this: If we have:

f {a : Nat := 0} {b : Nat := a + 1}  {c : Nat := a + b} := ...

Then if we find f we should generate the following:

let a := 0
     b := a + 1
     c := a + b
in f a b c;

Note that default arguments happens in FromConcrete.NamedArguments and in the aritychecker.
So if we have f {b := 1}, then the NamedArguments desugarer will generate

let a := _
     b := 1
in f {a} {b}

And the arity checker will introduce the final argument:

let a := _
     b := 1
in 
  let 
    c := a + b
   in  f {a} {b} {c}
@janmasrovira janmasrovira added enhancement New feature or request pending-review labels Oct 16, 2023
@janmasrovira janmasrovira added this to the 0.5.3 milestone Oct 16, 2023
@janmasrovira janmasrovira self-assigned this Oct 16, 2023
@janmasrovira janmasrovira linked a pull request Oct 17, 2023 that will close this issue
lukaszcz pushed a commit that referenced this issue Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pending-review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant