How to properly use fields from other records in F #?
I am currently learning F #, but I am struggling a bit with using records and using their fields. I would like to use fields from another record.
Let's say I want to define a Person record and a birthday record.
My code
type DateOfBirth =
{
Day: int;
Month: int;
Year: int;
}
type Person =
{
Name: string;
Birthday: DateOfBirth;
}
I have defined my both entries without any errors. Now I am trying to create an actual person instance, but I am getting an error in the following code at the line (Birthday.Day = 15;).
let John =
{
Name = "John";
Birthday.Day = 15;
Birthday.Month = 15;
Birthday.Year = 15;
}
An error message appears: "Namespace or module 'Birthday' not defined."
What am I doing wrong?
source to share
To close this issue, I've added @ildjarn's answer below as a link that could be accepted as an answer. The idea is that the DateOfBirth instance is specified for the Birthday property as a single unit, enclosed in a separate set of curly braces nested within the outer entity construct.
let John =
{
Name = "John";
Birthday = { Day = 15; Month = 15; Year = 15 }
}
source to share