After I put together a little C # after a long time, F #, I realized that “object constructors” are a good way to fool themselves into believing that they are dealing with a functional object.
Consider:
let x = new Something()
x.Key <- 1
x.Value <- 2
It seems very unclean due to a very obvious mutation of values. Especially if we store our objects once, it seems very unnecessary. In C #, you can initialize an object as follows:
var x = new Something() { Key = 1, Value = 2 };
It looks better, and in fact it seemed to me that I used the record (almost), obviously its just sugar, but its good sugar.
Q. Assuming we don’t have control over “Something” (pretending to be from a C # library), is it possible for F # to use this shorthand initialization, if not, why not?
user1158550