So, I spent some more time with this and analyzed the results of various syntactic variants in IL to see what F# is doing. As a result, I can see that as long as my fields are "just" mutables and not ref cells, they'll always get wrapped in a ref cell instance before being passed by reference.

Since using a ref cell is the only way I'm aware of to force the F# compiler to pass the variable by reference (IOW - generate the "Type&" IL instead of simply "Type"), the solution that uses ref cells for all my fields seems the best one because I avoid creating and dropping them all the time.

The difference in IL is this - passing by value:

call instance void

1
[ClassLibrary1]ClassLibrary1.Class1::TakeString(string)

Passing by reference:

1
call instance void [ClassLibrary1]ClassLibrary1.Class1::DoSomething(string&)

It seems kind of weird that the ref cells should be the only way to do this. If I have a mutable variable, why is there no way to say "pass it to this function by reference", IOW tell the compiler to generate "Type&" IL? I'm sure there's something I'm not seeing, but creating a load of ref cells in this use case seems like a great waste of time and resources.

Thanks
Oliver

By on 5/16/2008 12:11 PM ()

This problem was solved with help from Brian McNamara - he pointed me to the important other, apparently secret <g>, way of passing parameters by reference, which I suspected to be around the whole time. Please see my blog post for the solution: [link:www.sturmnet.org]

By on 5/17/2008 4:37 AM ()

Hi Oliver

Thanks again for taking the time to report the resolution for the issue!

Kind regards

don

By on 5/20/2008 3:58 AM ()
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