Hi Edward,

first of all a comment. Although you can use let _ to ignore results it is better to use |> ignore idiom, it is easier to read.

The problem you are experiencing it is due to the fact that assemblies retain information about linked assemblies and this happens when you compile the C# code with a reduced version of the F# code. When the F# compiler tries to compile and link the full .fs code you refer the C# assembly that in its turn refers to the previous version of the assembly you are attempting to compile.

In this case the circular reference can be broken as follows. foo.cs file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using System.Windows.Forms;

namespace WinApp
{
  public class Form1 : Form
  {
    public Core.myRec _MyRec;
    
    public Form1()
    {
//      InitializeComponent();
    }
    
    public Core.myRec MyRec  // Record type declared in F# assembly 
    {
      set { _MyRec = value; }
      get { return MyRec; }
    }
  }
}

File core.fs:

1
2
3
4
5
6
#light

type myRec = {
  val1: string;
  val2: int;
}

File baz.fs:

1
2
3
4
5
6
7
8
9
10
11
open System 
open WinApp
open Core

#light

let aRec = { val1 = "hello"; val2 = 123 }
let t = new Form1()
t.MyRec <- aRec
t.ShowDialog() |> ignore
t.Dispose() |> ignore

The compilation commands are:

1
2
3
4
5
fsc -a core.fs

csc /r:"c:\Program Files\FSharp-1.9.3.3\bin\FSharp.Core.dll" /r:Core.dll /target:library foo.cs

fsc -r foo.dll -r core.dll baz.fs

Does this fully answer to your question?

Antonio

By on 11/19/2007 1:35 PM ()

Hi Antonio

Many thanks for your timely, thorough response: I really appreciate it, and it resolves the issue. For some reason I was convinced the circular reference couldn't be the source of the problem but alas I understand why it was causing a problem now.

And thank you for the 'pipeline to ignore' idiom, yes it is indeed much cleaner; I was wondering about that but had deferred clearing that up.

I am now a whole 4 days into F# and really enjoying it. I just received the _Foundations_ book (looks good, btw) and I was delighted to discover that my idea with respect to c# form/f# collaboration turns out to be a recommended approach.

Best regards

Edward

By on 11/23/2007 3:33 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