Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>it seems that when you use "let .. in" you can override the default "#light" setting which is that whitespace is significant, so I guess that's what happens in this case and why you don't get any warning/error in the second case (you added 'in', so the compiler thinks that you want to specify the scope explicitly). It seems a bit weird so it may be a bug. I'm sure Brian from the F# team will answer this doubt soon :-).</p> <p>Anyway, I think the compiler treats your second example just as (using an easier to compile example):</p> <pre><code>open System let ar = new ResizeArray&lt;_&gt;() in let rnd = new Random(); ar.Add(rnd.Next()) printfn "%A" (rnd.Next()) </code></pre> <p>You can force it to treat it as you wanted if you add parentheses and write something like this:</p> <pre><code>let ar = new ResizeArray&lt;_&gt;() in (let rnd = new Random() ar.Add(rnd.Next())) printfn "%A" (rnd.Next()) </code></pre> <p>In general, you can use parentheses to specify scopes in any place of the F# program. For example you can write:</p> <pre><code>let a = 1 (let a = a + 10 printfn "%d" a) printfn "%d" a </code></pre> <p>This example prints "10" and then "1". Of course, this doesn't seem to be very practical, but it is useful when using the <code>use</code> keyword that behaves like <code>let</code>, but works for <code>IDisposable</code> objects and ensures that the object is disposed when it leaves the scope (this is just like <code>using</code> in C#):</p> <pre><code>let some = new Some() (use file = new StreamReader(...) let txt = file.ReadToEnd() printfn "%s" txt) doSomething() // continue, 'file' is now closed! </code></pre> <p><strong>EDIT</strong>: I completely forgot to mention the important bit - the first way of writing the code seems more natural to me (and it fully uses the benefits of "simple" #light syntax that F# offers), so I would prefer it :-). </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