I want to implement IEnumerable<KeyValuePair<DateTime, 'T>> in my class and add mathematical operators to this class so that the operators can work as a built-in function for any numeric types 'T - automatically add constraints.
I just can't make the following code snippet. It does not work with or without the keyword "inline" in a memberβs ad.
Also, if I define a function
let inline add lr = l + r
before the type and use it instead of adding l.Value + r.Value, it also does not work.
Can someone please show me what I'm doing wrong?
Probably the whole approach is wrong, and is there a way to achieve the same goal in a different way?
namespace Test open System open System.Linq open System.Collections.Generic [<SerializableAttribute>] type TimeSeries<'T>(dictionary : IDictionary<DateTime, 'T>) = let internalList = new SortedList<DateTime, 'T>(dictionary) interface IEnumerable<KeyValuePair<DateTime, 'T>> with member this.GetEnumerator() = internalList.GetEnumerator() member this.GetEnumerator() : Collections.IEnumerator = internalList.GetEnumerator() :> Collections.IEnumerator member private this.sl = internalList static member inline (+) (left : TimeSeries<'T>, right : TimeSeries<'T>) = let res = query { for l in left do join r in right on (l.Key = r.Key) select (l.Key, l.Value + r.Value) } new TimeSeries<'T>(res |> dict)
type-inference f #
Vb
source share