-
Notifications
You must be signed in to change notification settings - Fork 833
Description
What
The following error message is generated from this code sample: -
let x = [ 1, 2, 3, 4, 5 ]
x |> List.map(fun x -> x + 5)
error FS0001: The type 'int' does not match the type 'int * int * int * int * int'
Why
Users new to F# often accidentally use , instead of ; for item separators as this is what they are used to. This is valid F# as you simply get a list with a single tupled item. You will probably get an compiler error (or an exception if you have simply indexed into the list) further down the line as you try to get at the "elements" of it. The user then has to work backwards to realise that they should have used ; instead of ,.
How
This is open to debate as to how this can consistently (and easily) be warned against. It's probably too late to do this where the real error is occurring, because (I would imagine) that by then all you have is a tuple with no context as to where it came from.
Perhaps an alternative approach would be to create a new warning which would be fired if the compiler identifies list with a single Tuple - happy to get ideas on this.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status