Hacker News new | ask | show | jobs
by gbin 586 days ago
In rust it would be:

  struct Foo(u32);
No?
1 comments

In C#, a now popular choice is

  record struct Foo(int Value);
In F#, this is instead done with

  // Foo and Bar cannot be assigned to each other
  type Foo = Foo of int
  type Bar = Bar of int

  // Foo and Bar can be assigned to each other
  type Foo = int
  type Bar = int
The first variant uses single-case unions. It's a bit unfortunate that they also default to classes over structs unless you annotate them with [<Struct>], partially fixed by escape analysis though.

The enum trick is the tersest and will also serialize correctly in most cases, but I have never seen anyone use it like that before.