Go’s structs are typed collections of fields. They’re useful for grouping data together to form records.
This person struct type has name and age fields.
newPerson constructs a new person struct with the given name.
F# uses garbage collection; you can safely return a newly created object - it will only be cleaned up by the garbage collector when there are no active references to it.
To run the code, compile and execute with your preferred F# compiler.
Output:
An anonymous type can be used when a struct definition is only needed for a single use case, like in table-driven tests.
Now that we can work with structs in F#, let’s learn more about the language.