I need a data structure for the following:
In a device having memory slots, each of the slots has a set of parameters. These parameters are of different types. The list of possible parameters is fixed, so there is no need for general flexibility à la "Support for arbitrary parameters without changes". In addition, a content structure is known for each parameter. Typical examples of use are the extraction and modification of one particular parameter, as well as the conversion of a complete set of parameters to another (but already defined) data structure.
A natural choice for an F # data structure would be a type of sum like this:
type SomeParameterContentType = { Field1 : string, Field2 : int } type SomeOtherParameterContentType = { Other1 : bool option, Other2 : double } type Parameter = | SomeParameter of SomeParameterContentType | SomeOtherParameter of SomeOtherParameterContentType
Thus, I could create a set and save the parameters there with a very good data structure. The question here is: given this idea, what would a particular parameter look like? I do not know how to specify a predicate for the find function for sets. One could define another type of sum, listing only the types of parameters without their contents, using this as a key for the Dictionary, but I do not really like this idea. Using strings instead of the second type of sum does not improve the quality, since this requires a further two times to provide a list of possible parameters.
Does anyone have a better idea?
thanks --Mathias.
source share