fsharp / fsharp/fslang-suggestions

Allow comma and parentheses for tuple type signatures

Open
#1,129 27 comments 26 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

approved-in-principle area: syntax Theme-Simple-F#
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

Allow comma and parentheses for tuple type signatures

I propose we allow using a comma and parentheses in declaring tuples in type signatures. A type signature 't * 'u could be rewritten as ('t, 'u). For example:

type Demo =
    abstract member f : int * string            // current tuple declaration
    abstract member g : (int, string)           // would be equivalent to `g` with this suggestion

    abstract member h : seq<int * string>       // current tuple instantiation of type arg
    abstract member i : seq<int, string>        // should still fail - seq only takes one type arg
    abstract member j : seq<(int, string)>      // would be equivalent to `i` with this suggestion
    abstract member k : Map<int, string>        // should continue to work as before - no parens, not a tuple
    abstract member l : Map<int, int * string>  // current tuple instantiation of type arg
    abstract member l : Map<int, (int, string)> // 'TKey = int, 'TValue = int * string aka (int, string)

The existing way of approaching this problem in F# is using the existing 't * 'u syntax.

Pros and Cons

The advantage of making this adjustment to F# is bringing the type signature syntax inline with the implementation syntax. Defining a tuple as 't * 'u but implementing it as x, y is a common stumbling block for first time F#ers.

The disadvantages of making this adjustment to F# are:

  • Having two ways to say the same thing
  • Moving further from ML style
  • Breaking change? I don't think that it is a breaking changes as type signature with this syntax does not compile currently, but I might be missing a corner case in my assumption on that.

Extra information

Estimated cost (XS, S, M, L, XL, XXL):

Related suggestions: (put links to related suggestions here)

Affidavit (please submit!)

Please tick this by placing a cross in the box:

  • This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
  • I have searched both open and closed suggestions on this site and believe this is not a duplicate
  • This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.

Please tick all that apply:

  • This is not a breaking change to the F# language design
    See note in Disadvantages
  • I or my company would be willing to help implement and/or test this

For Readers

If you would like to see this issue implemented, please click the 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.

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 the proposed tuple-signature examples in this issue, especially the seq and Map cases, and check whether the syntax distinctions are fully specified. Done would mean an agreed language-design decision and an implementation and test plan for accepting parenthesized comma syntax without changing existing generic type-argument behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.