reasonml / reasonml/reason

Syntax for function expressions with attributes is verbose

Open
#2,331 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
OCaml
Stars
10.3k
Forks
438
PR merge metrics
No merged PRs in 30d

Description

Currently if I want to get an attribute on an inner function expression I have to break it out, expose an extra arrow, and add some (really unintuitive) parens:

let foo =
  [@attrOnBar]
  (
    (bar) =>
      [@attrOnBaz]
      ((~baz) => [@attrOnQux] ((~qux=?, ()) => {"bar": bar, "baz": baz}))
  );

I would be interested in having a syntax like:

let foo = (
  [@attrOnBar] bar,
  [@attrOnBaz] ~baz,
  [@attrOnQux] ~qux=?,
  (),
) => {"bar": bar, "baz": baz};

This would basically be an extension of the refmting of nested function expressions to a parens style call syntax that also includes attributes - so I think the first version should be valid, but would refmt to the second.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with refmt's handling of nested function expressions and attributes, using the two syntax examples in the issue as the behavioral guide. Done means the compact attribute-bearing function-expression syntax is accepted and refmt produces the proposed form while the existing form remains valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.