Records should be able to marked with the Struct Attribute

Oct 9, 2014 at 8:05 PM
This is coming from a work-in-progress PR from here: https://github.com/fsharp/fsharp/pull/298

The idea is simple: record types can be marked with the Struct attribute therefore making the record be a value type.

I've gotten a lot of feedback from developers really wanting this feature.

I've started a branch working on this, not sure if I should make this into a pull-request because it is not finished. https://visualfsharp.codeplex.com/SourceControl/network/forks/TIHan/fsharp?branch=struct_records

I still have some big issues:
  • You can construct the record using the default ctor, ex: vec3 ().
  • Incorrect call generation on using the struct record as a argument of type: object; meaning, it does not box and/or constrain the value type.
  • Pickler code may not be favorable (needs review)
Editor
Oct 10, 2014 at 4:35 PM
Could you add this to http://fslang.uservoice.com and cross-link here? I'm in favour of this feature but we should get it recorded on fslang.uservoice.com so people can discuss it there and for long term visibility. Strangely it doesn't seem to have been recorded there already.

There is a related proposal here - https://fslang.uservoice.com/forums/245727-f-language/suggestions/6147144-allow-single-case-unions-to-be-compiled-as-structs I'm also in favour of that one. Ideally both would be dealt with in the same F# langauge version.

I agree you shouldn't be able to call the default constructor.
Oct 10, 2014 at 7:41 PM