it seems that when you use "let .. in", you can override the default "#light" parameter, which is that the space is significant, so I think that what happens in this case and why you don’t you get warnings / errors in the second case (you added "to", so the compiler thinks that you want to explicitly specify the area). This seems a little strange, so it could be a mistake. I'm sure Brian from the F # team will soon answer this doubt :-).
In any case, I think the compiler treats your second example the same way (using a simpler compilation example):
open System let ar = new ResizeArray<_>() in let rnd = new Random(); ar.Add(rnd.Next()) printfn "%A" (rnd.Next())
You can get it to handle it the way you like if you add parentheses and write something like this:
let ar = new ResizeArray<_>() in (let rnd = new Random() ar.Add(rnd.Next())) printfn "%A" (rnd.Next())
In general, you can use parentheses to indicate areas anywhere in your F # program. For example, you can write:
let a = 1 (let a = a + 10 printfn "%d" a) printfn "%d" a
In this example, "10" is printed, and then "1". Of course, this is not very practical, but it is useful to use the use keyword, which behaves like let , but works for IDisposable objects and ensures that the object will be deleted when it leaves the scope (this is similar to using in C #):
let some = new Some() (use file = new StreamReader(...) let txt = file.ReadToEnd() printfn "%s" txt) doSomething() // continue, 'file' is now closed!
EDIT : I completely forgot to mention the important bit - the first way to write the code seems more natural to me (and it takes full advantage of the "simple" #light syntax that F # offers), so I would prefer :-).
Tomas petricek
source share