Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The F# type checking mechanism is more strict than the type checking in C# in a number of ways. One aspect of this is that F# does not do any implicit conversions behind the scenes and so you have to use the right numeric literals (like <code>1.0f</code>) or explicit conversion functions (like <code>float32</code>).</p> <p>Why is the language designed in this way? One reason is that it makes type inference simpler and more predictable. For example:</p> <pre><code>let data = [| 0; 1; 2 |] let writeData n = data.[0] &lt;- n </code></pre> <p>Here, the F# compiler knows that <code>data</code> is of type <code>int[]</code> (because it is initialized to an array containing integers). It also knows that <code>writeData</code> is a function <code>int -&gt; unit</code> because the array contains integers and so <code>n</code> has to be an integer too.</p> <p>If the compiler did implicit conversions, there would be a lot of uncertainties:</p> <ul> <li><code>data</code> could be, for example, <code>float[]</code> or <code>float32[]</code> because you could implicitly convert the integers to other numeric types</li> <li><code>dwriteData</code> could take any numeric type that is convertible to <code>int</code> (such as <code>int16</code>, <code>sbyte</code> etc.)</li> </ul> <p>This would make the type information a lot more complicated and you'd probably have to specify types explicitly more often. For this reason, F# chooses a tradeoff - you have to write conversions explicitly, but then you do not need to use type annotations as often.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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