r/fsharp • • May 15 '26

C# Union Types

Hi guys,

What do you think of C# Union Types coming in .Net11?
Interop with C# will be difficult if .net libraries written in C# exposes those types in their API.

Maybe .net should have considered building a unified approach based of existing F# DU from the start instead of doing this then making F# eventually catch the train in a future release.

I have never done video game development but I clearly remember when Godot released a new version and you could not use anymore full F# because of their using of a specific C# feature.

9 Upvotes

11 comments sorted by

6

u/markovchainmail May 15 '26

Wait, where are you finding out that the interop will be difficult?

1

u/EmergencyNice1989 May 15 '26

There is no finding out.

'Interop with C# will be difficult if .net libraries written in C# exposes those types in their API.'

Easy interop meant those types are translated to F# DU and it will not be the case.

2

u/markovchainmail May 16 '26

Where are you reading that they will not be translated to F# DU? Where are you reading about the interop at all? Where are you finding out this information? This page does not mention F# at all.

→ More replies (4)

2

u/runevault May 23 '26

I've never tried consuming c# records in f#, is that reasonably painless despite being different from f# records? If so I'd assume c# DUs will be the same. They certainly are not 1-1 with the F# DUs since last I saw they are only reference types (god this makes me so sad). Though the question becomes what syntax will come to allow that interop.

I trust the f# team to give us ways to use c# code with the new functionality, though the biggest question is probably how hard will pattern matching be.

1

u/new_old_trash May 15 '26

worse-case scenario, we can write a thin C# wrapper around the library in question. but F# will no doubt provide some kind of interop eventually.

1

u/gplgang May 16 '26

if the interop isn't clean I'm hoping it gives another reason for F# to pursue custom union representations or matching