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

Named arguments #2250

Merged
merged 3 commits into from
Jul 18, 2023
Merged

Named arguments #2250

merged 3 commits into from
Jul 18, 2023

Conversation

janmasrovira
Copy link
Collaborator

@janmasrovira janmasrovira commented Jul 10, 2023

This pr implements named arguments as described in #1991. It does not yet implement optional arguments, which should be added in a later pr as they are not required for record syntax.

Syntax Overview

Named arguments are a convenient mehcanism to provide arguments, where we give the arguments by name instead of by position. Anything with a type signature can have named arguments, i.e. functions, types, constructors and axioms.

For instance, if we have (note that named arguments can also appear on the rhs of the :):

fun : {A B : Type} (f : A -> B) : (x : A) -> B := ... ;

With the traditional positional application, we would write

fun suc zero

With named arguments we can write the following:

  1. fun (f := suc) (x := zero).
  2. We can change the order: fun (x := zero) (f := suc).
  3. We can group the arguments: fun (x := zero; f := suc).
  4. We can partially apply functions with named arguments: fun (f := suc) zero.
  5. We can provide implicit arguments analogously (with braces): fun {A := Nat; B := Nat} (f := suc; x := zero).
  6. We can skip implicit arguments: fun {B := Nat} (f := suc; x := zero).

What we cannot do:

  1. Skip explicit arguments. E.g. fun (x := zero).
  2. Mix explicit and implicit arguments in the same group. E.g. fun (A := Nat; f := suc)
  3. Provide explicit and implicit arguments in different order. E.g. fun (f := suc; x := zero) {A := Nat}.

@janmasrovira janmasrovira added this to the 0.5 milestone Jul 10, 2023
@janmasrovira janmasrovira self-assigned this Jul 10, 2023
@janmasrovira janmasrovira force-pushed the named-arguments branch 5 times, most recently from 90cbfa4 to 94d07d7 Compare July 14, 2023 13:06
@janmasrovira janmasrovira marked this pull request as ready for review July 17, 2023 08:47
commit a9fd159
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Fri Jul 14 17:33:53 2023 +0200

    ormolu

commit c5a312b
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Fri Jul 14 17:32:22 2023 +0200

    improve message

commit 108c353
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Fri Jul 14 17:27:04 2023 +0200

    test

commit fbaeadd
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Fri Jul 14 16:19:13 2023 +0200

    add test

commit 94d07d7
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Fri Jul 14 15:06:15 2023 +0200

    optional delims

commit cb767c3
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Fri Jul 14 12:24:10 2023 +0200

    add error message for missing arguments

commit 617bc01
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Fri Jul 14 09:57:44 2023 +0200

    handle ambiguous iterators

commit 6e0370e
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Fri Jul 14 07:43:44 2023 +0200

    fix bugs and add errors

commit fabe021
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Thu Jul 13 19:14:31 2023 +0200

    fix

commit 398c682
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Thu Jul 13 17:07:03 2023 +0200

    debugging

commit b9c41c5
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Thu Jul 13 15:21:51 2023 +0200

    wip

commit 243d2f7
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Thu Jul 13 01:42:37 2023 +0200

    translating named args

commit a4553a4
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Tue Jul 11 19:35:27 2023 +0200

    wip

commit 9854f64
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Tue Jul 11 17:22:42 2023 +0200

    add named signature builder

commit e94631d
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Tue Jul 11 00:45:31 2023 +0200

    wip

commit f912bee
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Mon Jul 10 19:29:23 2023 +0200

    ambiguousiteratortype

commit a872a39
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Mon Jul 10 18:31:40 2023 +0200

    wip

commit 5de2cf1
Author: Jan Mas Rovira <janmasrovira@gmail.com>
Date:   Mon Jul 10 16:54:13 2023 +0200

    style
@paulcadman paulcadman self-requested a review July 17, 2023 09:10
@janmasrovira janmasrovira marked this pull request as draft July 17, 2023 14:32
@janmasrovira janmasrovira marked this pull request as ready for review July 17, 2023 17:51
Copy link
Collaborator

@paulcadman paulcadman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌟

@paulcadman paulcadman merged commit 2d666fd into main Jul 18, 2023
8 of 12 checks passed
@paulcadman paulcadman deleted the named-arguments branch July 18, 2023 09:32
@jonaprieto jonaprieto modified the milestones: 0.5 , 0.4.2 Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional and named arguments
3 participants