-
Notifications
You must be signed in to change notification settings - Fork 833
Closed
Labels
Feature ImprovementTheme-Simple-F#A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.
Milestone
Description
What
The following code snippet returns an error message which could be improved upon:
let foo2 = Seq.map((*) 2) >> Seq.filter(fun x -> x < 10) // not okerror FS0030: Value restriction. The value 'foo2' has been inferred to have generic type
val foo2 : ('_a -> seq<int>) when '_a :> seq<int>
Either make the arguments to 'foo2' explicit or, if you do not intend for it to be generic, add a type annotation.
Why
This error is confusing in several ways: -
- Explicitly providing the argument and moving from
>>to|>removes the error e.g.
let foo a = a |> Seq.map((*) 2) |> Seq.filter(fun x -> x < 10) // ok- It is unfortunate that the compiler has correctly determined that
seq<int>would be acceptable yet cannot use it. - Whilst the error message gives a couple of solutions, an example would help for both, or a URL to read up more on it. Also, the error message doesn't include a "why" this occurs. Granted, this may be too complex to do in this error message in this case, but I think that we should explore it nonetheless.
How
Open to suggestions here! Based on discussions with @swlaschin, @colinbull and @mavnn there are a few options. Let's start with this text: -
A let binding without a parameter creates a simple value and not a function. As this code is generic it has caused a value restriction. Consider adding a type annotation (or explicitly adding a parameter) to make this a function.
Metadata
Metadata
Assignees
Labels
Feature ImprovementTheme-Simple-F#A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.
Type
Projects
Status
Done