Join Kit Eason for an in-depth discussion in this video Struct unions, part of What's New in Visual Studio 2017 for F# For Developers.
- [Instructor] Okay let's round out our explanation…of struct types in F# 4.1…by looking at struct unions.…So here we have a little revision…of how unions looked before.…We've got a type called point.…It's got two cases on line six and seven, 2D and 3D,…and each case has got some floats.…Two floats for 2D and three floats for 3D…so that should be fairly familiar with you…as an F# developer.…However you make this into a struct…so it's allocated on the stack…and I'm just going to make a copy of that.…
Here are the different names…just so we can test them independently for performance…and the first thing I need to do is…put an attribute on there.…You'll see if I just do that I get a compiler error…and that's saying if a union type has more than one case…and is a struct,…then all fields within the union type…must be given unique names.…So I'm going to go and call this one x2…and this one y2…and this one x3, y3,…and surprise, surprise, z3.…
So now all those cases have different names.…Let's try sending all that into F# interactive.…
Kit Eason discusses the new value types that provide an opportunity for performance gains, the new result type which gives you access to the railway oriented programming style of error handling, and program organization and readability changes. Plus, he explores the evolution of tooling for F#, and explains how F# tooling has changed in Visual Studio 2017. To wrap up the course, he shares how you can contribute to the F# language and tooling by getting involved in the open-source community.
- Working with struct tuples
- Marking a record type as a struct value
- Marking a discriminated union as a struct type
- Using the fixed keyword to mark a value
- F# result type and associated functions
- Resolving potential naming clashes between modules and types
- Error message improvements
- The past and future of visual F# tooling in Visual Studio
- Reviewing F# tooling changes