Hide this comment

I can't reproduce the problem with F# 1.9.6.16 in VS2008, neither in Release nor in Debug mode.

Do you still have the problem, when you put the code into a function? Could you provide a sample with code that does something useful?

By on 7/1/2009 2:55 PM ()Reply
Hide this comment

I can't reproduce the problem with F# 1.9.6.16 in VS2008, neither in Release nor in Debug mode.

Do you still have the problem, when you put the code into a function? Could you provide a sample with code that does something useful?

Of course! I uploaded a simple project [1]. With this one, the compiler does something more bizarre: it creates a tuple, but only uses the first item.

[1] [link:www.ezbakhe.es]

By on 7/1/2009 3:57 PM ()Reply
Hide this comment

Ok, now I was able to reproduce the problem. Apparently the code generator has an issue with mutable indices to arrays. You should report this bug to fsbugs (at) microsoft (dot) com

The fact that the compiler creates a temporary tuple is not as bizarre as you might think. I suppose the reason for this behaviour is that it internally represents the array setter as a function taking a tuple with 2 elements: the index and the value. Normally the tuple code gets "optimized away", but in this case the mutability of the index seems to prevent that.

A small repro sample:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module _Test.Test

let loop n =
    let a = Array.zeroCreate n    
    let mutable i = -1
    for j = 1 to n do
        i <- i + 1        
        a.[ i ] <- j // creates an unnecessary temporary tuple
        //let i = i in a.[ i ] <- j // has no problem        
    a

[<EntryPoint>]
let main(args) =
    printfn "%A" (loop 10)
    0
By on 7/2/2009 3:23 AM ()Reply
Hide this comment

I've forwarded this thread to the fsbugs alias Stephan mentioned - thanks for reporting the issue.

Kind regards

don

By on 7/5/2009 12:44 PM ()Reply
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper

Logging in...