Comment by rawling
20 hours ago
A record wrapping a string, indicating what the string represents, so you can't mix it up with a different thing also represented by a string.
20 hours ago
A record wrapping a string, indicating what the string represents, so you can't mix it up with a different thing also represented by a string.
Yes, you can have two different record types which both wrap a string value.
As a (bad) trivial example, you could wrap reading a file in this kind of monstrosity:
Now, such an example would be an odd way to do things ( particuarly because we're not actually avoiding the try/catch inside ), but you get the point. Both FileRead(string value) and FileError(string value) wrap strings in the same way, but are different record types, and the union FileResult ties them back together in a way where you can tell which you have.
It's more useful implemented a level deeper, so that the exception is never raised and caught, because exceptions aren't particularly cheap in .NET.