Skip to content

RFC FS-1353 - Parameterless struct constructors and struct initializers - #855

Open
xperiandri wants to merge 2 commits into
fsharp:mainfrom
xperiandri:rfc/fs-1353-parameterless-struct-constructors
Open

xperiandri wants to merge 2 commits into
fsharp:mainfrom
xperiandri:rfc/fs-1353-parameterless-struct-constructors

Conversation

@xperiandri

Copy link
Copy Markdown
Contributor

Click “Files changed” → “⋯” → “View file” for the rendered RFC.

Summary

F# struct types can declare a public parameterless constructor (new() = ... or type S() = ...). Structs with a primary constructor can contain instance let, do and member val definitions, the F# counterpart of C# 10 struct field initializers. S() calls a public parameterless constructor and otherwise zero-initializes, as in C#. For a struct with such initializers, S() never zero-initializes; Unchecked.defaultof<S> still does. Non-public parameterless constructors of imported structs are ignored, as in C#. Gated by a preview feature; no FSharp.Core change.

Both suggestions are approved in principle: #362 (parameterless constructors in structs) and #1056 (do bindings in structs).

Current behaviour the RFC starts from

F# column checked with SDK 11.0.100-rc.1; C# column from the C# 10 proposal, with new S() and CS8958 checked on the same SDK.

Case F# today C#
new() = ... / type S() = in a struct FS0870 / FS0081 allowed, must be public (CS8958)
let / do / member val in a primary-constructor struct FS0901 / FS0035 / FS0901 field initializers allowed
S() on a C# struct with public S() calls it calls it
S() on an IL struct with a private or internal parameterless constructor FS0801 zero-initializes
new 'T() for that IL struct compiles, MissingMethodException at run time same
Unchecked.defaultof, Array.zeroCreate, [<DefaultValue>] field, omitted [<Optional>] argument zero, constructor not run zero
<@ S() @> NewObject with a constructor, DefaultValue without –

Related

🤖 Generated with Claude Code

xperiandri and others added 2 commits September 11, 2026 20:10
Covers fslang-suggestions fsharp#362 and #1056, both approved in principle,
for parity with C# 10 parameterless struct constructors and struct
field initializers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@xperiandri

Copy link
Copy Markdown
Contributor Author

If it makes sens to describe only the difference with classes that may be shorter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant