Skip to content

Support for optional arguments #355

@Sam647254

Description

@Sam647254

I've been learning and using Mint for a couple of weeks now, and I'm enjoying the language so far. One feature that I miss in JavaScript/TypeScript is the ability to make arguments optional by specifying a default value:

function f(a, b = 0) {
  return a + b;
}

The idea that I have for Mint is something like this:

fun f(a : Number, b : Number = 0) : Number {
  a + b
}

Since type inference exists already for properties, optional arguments can have their types omitted as well:

fun f(a : Number, b = 0) : Number {
  a + b
}

One obvious issue that I can think of is that it won't mix well with partial application, since now f(a) could mean either partially applying the function or calling it with the optional argument. This can be solved by introducing a syntax for disambiguating the two scenarios, something like f(a) for the optional argument case, and f(a ...) for the partial application case.

I can help with the implementation.

Edit: Added the last sentence.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions