Note that there are some explanatory texts on larger screens.

plurals
  1. POf# Statically resolved types in type members
    primarykey
    data
    text
    <p>I want to implement <code>IEnumerable&lt;KeyValuePair&lt;DateTime, 'T&gt;&gt;</code> in my own class and add math operators to that class so that the operators could work like inline function on any numeric types of <code>'T</code> - automatically add constraints.</p> <p>I just cannot make the following piece of code work. It doesn't work neither with nor without 'inline' keyword at the member declaration.</p> <p>Also, if I define a function</p> <pre><code>let inline add l r = l + r </code></pre> <p>before the type and use it instead of addition l.Value + r.Value, it also doesn't work.</p> <p>Could someone please show me what I am doing wrong?</p> <p>Probably the whole approach is wrong and there is a way to achieve the same goal the other way?</p> <pre><code>namespace Test open System open System.Linq open System.Collections.Generic [&lt;SerializableAttribute&gt;] type TimeSeries&lt;'T&gt;(dictionary : IDictionary&lt;DateTime, 'T&gt;) = let internalList = new SortedList&lt;DateTime, 'T&gt;(dictionary) interface IEnumerable&lt;KeyValuePair&lt;DateTime, 'T&gt;&gt; with member this.GetEnumerator() = internalList.GetEnumerator() member this.GetEnumerator() : Collections.IEnumerator = internalList.GetEnumerator() :&gt; Collections.IEnumerator member private this.sl = internalList static member inline (+) (left : TimeSeries&lt;'T&gt;, right : TimeSeries&lt;'T&gt;) = 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&lt;'T&gt;(res |&gt; dict) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload