(i) Use

1
let dict = new Dictionary<IInterface1, IInterface2> (Collections.HashIdentity.Structural)

This really should have been listed as a breaking change - sorry!

(ii) use

1
type genericEventPair<'a> = trigger<'a> * IEvent<'a>;;

or else give an exact type in place of the "_". You can work out the exact type by replacing "_" with "int" and seeing what type is reported in the errors you get.

don

By on 12/6/2006 3:03 PM ()

Don,

Thanks for your help.

Chris

By on 12/7/2006 12:06 PM ()

Hi,

I wasn't sure if I should start a new thread for this as this one seemed kinda appropriate.

In the F# manual, under the section of calling F# code from C#, the part that talks about discriminating unions mentioned that you can use something like x.IsA() from C# to check if x was constructed with the A constructor.

This doesn't seem to work for me when I compile the code with F# 1.1.13.8 while the same code runs fine when compiled with 1.1.11.7.

On a side note libraries created with the new version of F# appear to be considerably larger when compiled with --standalone, compared to those compiled with 1.1.11.7.

Ivan

By on 12/9/2006 2:01 AM ()

Try checking if the methods have become static methods associated with the type.

Static methods are used be necessity whenever "null" may be used as a representation for the discriminated unions. An unintended change was made in 1.1.13.8 which means the section on discriminating on F# discriminated unions from C# code in the manual at page [link:research.microsoft.com] is not strictly correct. There it claims that "null" will only be used by the F# compiler for discriminated unions with <i>exactly 2<i> constructors, and where exactly one of those constructors is nullary. Indeed, it turns out that in 1.1.13.8 "null" will be used as a representation whenever there is precisely one nullary constructor and more than one non-nullary constructor. Of course you don't notice this from F# code. However you will have seen a repreesntation change from C# for types such as <code lang=fsharp> type x = | Alt1 | Alt2 of string | Alt3 of int </code> We apologise for this change, which was made as part of an effort to improve performance - indeed using "null" is often a performance gain. Given it has been released we're evaluating whether to change the specification or keep the behavior, however we're also lokoing into techniques to see if it will be possible to avoid using "null" at all for any F# types without any signficant change in performance (the primary types where this gives important performance gains are "list" and "set"). We'll get back to you. Don

By on 12/9/2006 7:11 AM ()

Interesting.

So how would I go about getting this to work with 1.1.13.8:

TestFS.fs:

-----------

1
2
3
4
5
namespace Test

type T = A of int | B of string | C

TestCS.cs:

-----------

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
namespace Test


{


    


class Test


{


    public static void Main(string[] args)


    {


        Test test = new Test();


    }

    public Test()


    {


        T t = T.A(5);

        System.Console.WriteLine(t.IsA());


        System.Console.WriteLine(t.IsB());


        System.Console.WriteLine(t.IsC());


    }


}

}

-------------------

I've tried replacing t.IsA/B/C() with T.IsA/B/C(t) but that didn't work.

Ivan

By on 12/10/2006 3:14 AM ()

You are right - the IsA, IsB and IsC methods have not been generated for this type.

We will be fixing these problems by reverting to the original specification for the representation of these discriminated unions, so in the next release your original code will work correctly. Until then by far the easiest workaround is to adjust the original F# code so it is not one of the discriminated unions where this behaviour occurs. This is best done by using a fake "unit" argument, i.e.

1
2
3
4
5
 

type T = A of int | B of string | C of unit

If that is not feasible (e.g. you don't have control over the F# code you're using), then you can compare tags rather than use IsA, IsB and IsC :

1
2
3
4
5
6
7
 

System.Console.WriteLine(T.GetTag(t) == T.tag_A);
System.Console.WriteLine(T.GetTag(t) == T.tag_B);
System.Console.WriteLine(T.GetTag(t) == T.tag_C);

Don

By on 12/10/2006 5:44 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