Skip to content

Change default reported type for arrays #635

@ReedCopsey

Description

@ReedCopsey

I propose we change F# lists reported type annotations to always use array instead of []. The existing default causes significant confusion, especially to people new to F#.

For example, the following output in FSI is incredibly confusing because it's apparently inconsistent to new users:

> let x = []
let y = [| |];;
val x : 'a list
val y : 'a []

While lists are declared using [ ], the type annotation shows list. Arrays, however, are declared using [| |], but the type annotation shows [], which "looks like an array" to new users. We very frequently get questions from people who are very confused when coming to F# because of this.

I propose to change type annotations which are reported (tooltips, FSI, intellisense) to display as this instead:

> let x = []
let y = [| |];;
val x : 'a list
val y : 'a array

Note that I am not suggesting changing or breaking compatibility. Using [] should still be allowed in manual type annotations. Today, you can easily use [] or array interchangeably. I am merely suggesting that all tooling should switch to suggesting array, as it'd be more in line with list, but also less confusing to new users.

Pros and Cons

The advantages of making this adjustment to F# are consistency for new users. Arrays would be obvious as arrays instead of being confused as lists.

The disadvantages of making this adjustment to F# are that it's a change from previous behavior.

Extra information

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

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
  • I or my company would be willing to help implement and/or test this

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