Regarding the requirement to cast a class to an interface.

My understanding is that this is partially a language philosophy issue. Since the class doesn't actually implement the method on its own then the method isn't really part of the class.

C# on the other hand goes ahead and saids Hey this FooBar method isn't in the classes method vtable but I found it under this interface that the class implemented so I'll use it instead.

The C# way is very convenient. The F# theory is good in that if I'm using interface methods to code by, why don't I just go ahead and use the interface type instead. This way my function isn't tied to the specific implementation type, this is really the issue with type inference. Its just a different way of thinking about the types as restriction on what I'm willing the function to work with.

By on 5/21/2009 3:49 PM ()

The problem is that by defining the signature of the interface method Move as:

1
2
3
4
type IPlayer =

    abstract member Move : string -> int*int -> unit    

the compiler is treating the int*int as addtional NON-tupled arguments, if you enclose the int*int in parens

1
2
3
4
type IPlayer =

    abstract member Move : string -> (int*int) -> unit    

then the compiler interprets the interface method as taking a string and Tuple of int*int.

That will then allow you to code the way you would normally in F#

this now compiles properly:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
type IPlayer =

    abstract member Move : string -> (int*int) -> unit

    

type ConsolePlayer(name:string) =

    interface IPlayer with

        member p.Move a scores =

            ()
By on 5/21/2009 3:37 PM ()

Thanks.

Though, this does not allow me to ''untuple'' the arguments in the member declaration. While I not saying you should be able to do both, the old CTP allowed it.

Also about the interfaces. While I can see the the clear separation, when there is talk about a partial implementation of interfaces, using the interface methods on the class should be right up there in the discussion.

By on 5/21/2009 4:59 PM ()

You just have to pattern match on the argument note the extra set of parens

1
2
3
4
member p.Move board ((s1,s2)) =

    ()

you could also:

1
2
3
4
member p.Move board ((s1,s2) as scores) =

    ()

I agree on the interface issue. I do find it irritating at times that I need to cast as much as I do.

By on 5/21/2009 5:36 PM ()
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