There's a good sample on the wiki:

[link:www.strangelights.com]

You're interface would look something like:

1
2
3
4
5
type ITest = interface
    abstract Quantity : float32
        with get, set
    abstract SetValue : float -> unit
end

Fields can be added to interfaces using the keywords "val" and "val mutable", but I'm informed this is actually a bug and will be removed in a future version of the compiler.

By on 6/13/2006 12:01 AM ()

Robert,

Thanks.

Again I am having trouble with the syntax of the default property indexer. Here is the C# code.

public interface ITest

{

double this[string name1, string name2] { get; set; }

}

I could not find an example in the article that addressed this case.

Thanks in advance.

Chris

By on 6/13/2006 9:26 AM ()

This should do the trick:

type ITest = interface
abstract Item : string * string -> float with get,set
end

let x = { new ITest with get_Item(a,b) = 1.0 and set_Item(a,b,v) = () }

type CTest =
class
interface ITest with
member x.get_Item(a,b) = 1.0
member x.set_Item(a,b,v) = ()
end
end

By on 6/13/2006 2:42 PM ()

I've also extended the object model syntax section of the Wiki.

<i><A href="http://strangelights.com/fsharp/Wiki/default.aspx/FSharpWiki.ObjectModelSyntaxExamples">http://strangelights.com/fsharp/Wiki/default.aspx/FSharpWiki.ObjectModelSyntaxExamples<i></A>

By on 6/13/2006 3:14 PM ()

Thanks Don.

That was very helpful.

By on 6/13/2006 7:00 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