Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override ToString for discriminated unions and records #429

Closed
baronfel opened this issue Oct 20, 2016 · 7 comments
Closed

Override ToString for discriminated unions and records #429

baronfel opened this issue Oct 20, 2016 · 7 comments

Comments

@baronfel
Copy link
Contributor

baronfel commented Oct 20, 2016

Submitted by Vasily Kirichenko on 4/15/2015 12:00:00 AM
181 votes on UserVoice prior to migration

It's a pain and dirty to add override x.ToString() = sprintf "%A" x to every type in order to make String.Format() happy:

type T1 =
  { Id: int
    Version: string }
override x.ToString() = sprintf "%A" x

type DU =
| C1 of int
| C2
override x.ToString() = sprintf "%A" x

I think it's very easy to teach the compiler generate this override automatically for all user types.

Response

** by fslang-admin on 6/23/2016 12:00:00 AM **

Marking as planned, though we need to work out the details
Don Syme
F# Language and Core Library Evolution

Original UserVoice Submission

@kurtschelfthout
Copy link
Member

RFC was added.

@dsyme
Copy link
Collaborator

dsyme commented Nov 9, 2016

@kurtschelfthout I've added you as write-admin in this repo if you want to edit issue descriptions directly, thanks

@kurtschelfthout
Copy link
Member

@dsyme, will do. Thanks!

@dsyme
Copy link
Collaborator

dsyme commented Mar 1, 2017

This is now covered by the RFC and has already been implemented. Thanks all!

@Porges
Copy link

Porges commented Nov 6, 2017

Question from the sky: Is this implemented in such a way that it avoids the performance penalties of sprintf "%A"? (ie. is ToString a generated equivalent of the result of sprintf "%A", or does it just call it)

@cartermp cartermp added this to the F# 4.1 milestone Jan 21, 2019
@abelbraaksma
Copy link
Member

abelbraaksma commented Oct 1, 2022

New location of RFC: https://github.com/fsharp/fslang-design/blob/main/FSharp-4.1b/FS-1022-override-ToString-for-discriminated-unions-and-records.md.

This was implemented for F# 4.1.

@abelbraaksma
Copy link
Member

@Porges see here for more info: #919

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

No branches or pull requests

7 participants