Is there a way to check that the type in a Generic fuction is numeric?
What I really want is to make sure that I can perform math on it. I can't
figure out what to put in the Where clause to make sure that it will add,
multiply etc.
It is a bit of a sad story. As pointed out by others, this isn't
supported currently. The feature request has been there for ages, ever
since the first .NET 2.0 beta releases, when generics first appeared:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94264
If you read the comments on the ticket, it was actually supposed to
finally appear in .NET 4 in form of IArithmetic<T> interface with
methods corresponding to usual arithmetic operators, implemented by
all standard numeric types. Unfortunately, it ended up being cut from
that release.
The only consolation is that the ticket remains open, which means that
there are still plans to address it, eventually. Hopefully in the next
major framework release. The pressure to have it now is greater - not
only C# devs want it, but it would also greatly simplify overloading
of arithmetic operators in F#, and, in particular, finally allow
proper polymorphism for functions operating on numeric types. So I
hope the F# team is going to get their weight behind that, as they (I
think) did with tuples.