Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As I said in a comment, I think this is a bug. Here's my reasoning. When the compiler sees </p> <pre><code>let inline addSelf (Wrap x) = (Wrap x) + (Wrap x) </code></pre> <p>I think it should make roughly the following inferences:</p> <ol> <li>The argument is of type <code>Wrap&lt; ^t&gt;</code> for some fresh <code>^t</code>.</li> <li>Therefore <code>x</code> is of type <code>^t</code>.</li> <li>Thus, the operands on the right hand side are also both of type <code>Wrap&lt; ^t&gt;</code>.</li> <li>These values are being passed into the <code>(+)</code> operator. Therefore, <code>Wrap&lt; ^t&gt;</code> needs to support a static operator <code>(+)</code> of type <code>Wrap&lt; ^t&gt; * Wrap&lt; ^t&gt; -&gt; ^u</code> for some fresh type <code>^u</code>.</li> <li>The only static operator <code>(+)</code> defined on <code>Wrap&lt;_&gt;</code> has type <code>Wrap&lt; ^a&gt; * Wrap&lt; ^b&gt; -&gt; Wrap&lt; ^c&gt; when (^a or ^b) : (static member (+) : ^a * ^b -&gt; ^c</code>.</li> <li>Unifying type variables, the overall type of <code>addSelf</code> should be <code>addSelf : Wrap&lt; ^t&gt; -&gt; Wrap&lt; ^c&gt; when ^t : (static member (+) : ^t * ^t -&gt; ^c)</code></li> </ol> <p>The various type inference steps are tricky, so it's certainly possible that I'm missing something and this behavior is expected. On the other hand, the various type inference steps are tricky, so they are a bit buggy :). It's also concerning that you can't annotate the function and all subexpressions and get the code to compile:</p> <pre><code>let inline doStuff&lt; ^t, ^u when ^t : (static member (+) : ^t * ^t -&gt; ^u)&gt; ((Wrap x) : Wrap&lt; ^t&gt;) : Wrap&lt; ^u&gt; = ((Wrap x) : Wrap&lt; ^t&gt;) + ((Wrap x) : Wrap&lt; ^t&gt;) </code></pre> <p>You still get a compiler error with the mysterious reference to the fresh type parameters <code>^?12020</code> and <code>^?12021</code> (or whatever the unique ints are in your case). I think this shouldn't happen.</p>
 

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