3 ms·
You are writing C# like it's F#. In F# you can write union types that are also structs: [<Struct>] type Entry = | Message | Term | C
by dfgdghdf 6y ago
You are writing C# like it's F#. In F# you can write union types that are also structs:
[<Struct>]
type Entry =
| Message
| Term
| Comment
And like in Rust, you have pattern matching on them:
let computeFooForEntry entry =
match entry with
| Message -> 0
| Term -> 1
| Comment -> 2
- Ygg2 6y agoI'm not trying to. It's just a shallow type hierarchy. And I can achieve it with Interface. But I would prefer a solution that doesn't box.
- dfgdghdf 6y agoInterfaces don't have a compile-time size so I don't see how you can use avoid boxing if you want a collection of IFoo. (Optimized) discriminated unions have a size that is the max size of the possible types, plus a flag to indicate the type. This is the best you can hope for without boxing.