Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Jack's answer is correct. I'll add a bit more context. <code>(%%)</code> is the untyped splice operator (that is, it splices a <code>Quotations.Expr</code> into another typed or untyped quotation), while <code>(%)</code> is the typed splice operator (that is, it splices a <code>Quotations.Expr&lt;'t&gt;</code> for some <code>'t</code> into another typed or untyped quotation). <code>(a : ty)</code> is just a type annotation, so <code>(%%row : float[])</code> indicates that when <code>row</code> is spliced into the quotation the result is a <code>float[]</code>. Without this annotation, <code>%%row</code> could be a value of any type, and the compiler would be unable to infer what we mean by the <code>.[]</code> indexer (just as it can't infer the type of <code>arr</code> in <code>fun arr i -&gt; arr.[i]</code>).</p> <p>In case it's helpful, here are some alternative ways to express roughly the same thing as <code>&lt;@@ (%%row:float[]).[i] @@&gt;</code>:</p> <ul> <li><p>We can convert the untyped quotation to a typed quotation before splicing:</p> <pre><code>let typedRow = Quotations.Expr.Cast&lt;float[]&gt; row &lt;@@ %typedRow.[i] @@&gt; </code></pre> <p>Here we are using the typed splice operator <code>(%)</code>, so the compiler knows that <code>%typedRow</code> is a <code>float[]</code> and that the <code>.[]</code> operator is applicable.</p></li> <li><p>We can use a different way of indexing into the array so that F#'s type inference can determine the type of <code>%%row</code> without an annotation:</p> <pre><code>&lt;@@ Array.get %%row i : float @@&gt; </code></pre> <p>Here, the <code>Array.get</code> method takes an <code>'a[]</code> as an argument and we add a type annotation which indicates that the result is a float, so F# will infer that <code>%%row</code> is a <code>float[]</code>.</p></li> </ul>
 

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