Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inferred generic type definitions #850

Closed
5 tasks done
Happypig375 opened this issue Mar 10, 2020 · 2 comments
Closed
5 tasks done

Inferred generic type definitions #850

Happypig375 opened this issue Mar 10, 2020 · 2 comments

Comments

@Happypig375
Copy link
Contributor

Inferred generic type definitions

I propose we allow inferred generic type definitions.

The existing way of approaching this problem in F# is typing out the generic type definition yourself.

let d : System.Collections.Generic.IDictionary<int, bool> = dict [] // Full
let d : _<int, bool> = dict [] //Inferred

Pros and Cons

The advantages of making this adjustment to F# are

  1. Consistency with arrays, generic type parameters, functions...
let array : int[] = [|1|] // Full
let array : _[] = [|1|] // Inferred
let seq : seq<int> = seq { 1 } // Full
let seq : seq<_> = seq { 1 } // Inferred
let f : int -> int = id<int> // Full
let f : _ -> _ = id<int> // Inferred
  1. Conciseness - not needing to spell out the type all the time
  2. Convenience - only needing to specify the information needed for type inference

The disadvantages of making this adjustment to F# are enabling potential confusing signatures. However, existing inferred types prove that this is not the case.

Extra information

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

Related suggestions: No

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
@charlesroddie
Copy link

charlesroddie commented Mar 12, 2020

Types with inferred parameters are already overused.

Programmers will often use length as a measure of cleanness of code. This is an imperfect but natural measure. There will be a strong incentive to use this feature since it shortens code.

This will lead to inscrutable code that is more abstract than necessary and more complex to parse for both humans and the compiler.

open System.Collections.Generic
let d1: IDictionary<int, bool> = dict []
let d2 = dict(List.empty<int*bool>)
// Fewest characters, but the least comprehensible and least simple of the three.
let d3: _<int, bool> = dict []

Actually the best thing here is to use let d4 = dict<int,bool> [] which is both shortest and simplest, but if you didn't spot that you would end up making the wrong choice of d3.

@dsyme
Copy link
Collaborator

dsyme commented Jun 16, 2022

I don't see the need for this, and it is pretty much technically infeasible I think.

@dsyme dsyme closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants