As you've currently described the problem, unless 'a
is of a regular type, I don't see a type-safe solution available to you in any paradigm. As you noted in your question, you can use a non-generic interface or abstract base class but this approach is probably going to lead you down a route of type testing and unsafe casting at some point - this is definitely not a favourable option.
If you can refactor your descriptor then other options potentially become available. For supporting a variety of different things in a collection, F# is actually opens up some options compared to C# provided that you can specify, in advance, what the possible options are using discriminated unions.
Consider you have a sequence of selection descriptors which might be a float or an int, you could create:
type SelectionDescriptor =
|SelectionDescriptorInt of int
|SelectionDescriptorFloat of float
An example as a list:
let test =
[SelectionDescriptorInt 3; SelectionDescriptorFloat 7.0;
SelectionDescriptorFloat 19.7; SelectionDescriptorInt 0 ]
Then when you inspect the results you could perform pattern matching on each element. This doesn't compromise the type safety of the solution and the compiler will warn us if our checks aren't exhaustive.
Note: It would be very suboptimal to use this approach if the structure of the different items is regular, i.e. if you have int, float, int float, etc. you would be much better off using a seq<int*float>
or some other equivalent structured type.