Skip to content

Optional positional args and the need for unit #625

Closed
@chriswilty

Description

@chriswilty

https://rescript-lang.org/docs/manual/latest/function#optional-labeled-arguments

There are a couple of things about optional args that are not coder-friendly:

  1. Positional args cannot be optional (even if there is just one arg)
  2. The need for "unit" param/arg as a final positional arg even when all args are labelled

Is there no way to make this a nicer experience? Mixing positional and labelled args in general seems a slightly odd allowance, but particularly so if it is causing this "unit" oddness. A necomer to the language (e.g. me a couple of weeks ago) is not going to understand why this is necessary:

Note for the sake of the type system, whenever you have an optional argument, you need to ensure that there's also at least one positional argument (aka non-labeled, non-optional argument) after it. If there's none, provide a dummy unit (aka ()) argument.

The need for "a dummy unit argument" is precisely the kind of quirk that could turn people away from this language. We come here in search of something better than typescript, so if this is going to remain in the language, I think we deserve a more detailed explanation than "for the sake of the type system". What is the trade-off here, what are we gaining in exchange for needing to use the dummy unit arg?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions