I suggest we ...

Override `ToString` for discriminated unions and records

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.

181 votes
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Vasily Kirichenko shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

4 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...

F# Language

Feedback and Knowledge Base