You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type Record = {field1:int; field2:int}
let l : int = {Record.field1=0; field2=1}
Compiler says:
The type 'int' does not contain a field 'field2'
Why
The error message doesn't tell you what the actual error is.
Of course, the above example is trivial, but for example if you pass a record expression to a library function that needs a list, you get really confused.
type Record = {field1:int; field2:int}
let doSomething (xs) = List.map (fun {field1=x} -> x) xs
doSomething {Record.field1=0; field2=0}
The type 'Record list' does not contain a field 'field2'
How
The usual error message when a type does not match:
This expression was expcted to have type
'a list
but here has type
Record