Be kind, I am a complete newbie to F# (coming from C#). In reviewing a user control for my appointment book, I see it is built upon the class concept of a "Visit" being used to fill a datagrid. I would like to use an F# descriminated union to replace the C# Visit class, but can't get it right. After much reading, I can't seem to break my thinking in C#.
Conceptually, a "Visit" will always have an "appointmentTime", regardless of it having a name or anything else. Now from this point a visit can be several different things (the reason for a using a discrimated union):
- If the visit only has a name and posting time, then it is an appointment only.
- if the visit only has a appointment time, time of service and a name, then the person was here without an appointment, and is a "walk-in",
- if the visit has a name, appointment time, posting time, and service time, then it is an appointment which the person was seen -- "a kept appointment",
- if the visit only has an appointment time without a name or anything else, then it is available for use --"an open time slot".
In C#, this is a simple class:
public class Visit
{
DateTime? tservice {get; set;}
DateTime? tappointment {get; set;}
DateTime? tposted {get; set; }
string lastname {get; set; }
string firstname {get; set; }
DateTime birthdate {get; set; }
}
How can this be conceptually written as a discriminated union in F#? And how would I use match...with with it?
Any help or guidance is most appreciated.