Here is the implicit form

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#light


type DXForm (title) as f =


    inherit System.Windows.Forms.Form () as base


    do f.Text <- "Managed DirectX Test - " + f.t


    do f.Show ()


    member f.t = title


    


new DXForm ("F# game")
By on 8/18/2008 4:26 PM ()

Hi there

The F# team recommendation is to use the implicit class syntax wherever this is possible, especially once using the CTP release when it comes out.

Thanks

Don

By on 8/22/2008 9:30 PM ()

I believe this is the code that you are looking for:

#light

type DXForm = class
inherit System.Windows.Forms.Form as base

val f : strin

new(title) as this = { f = title; } then
this.Text <- "Managed DirectX Test - " + this.f
this.Show()
end

1.) In the current F# bits, after the class you are inheriting from you can specify 'as <ident>' which will bring<indent> into scope as a way to access the base class. Note that in the next F# release (due out very soon) 'base' has been added as a keyword and you won't need to do that.

2.) The error you are seeing with 'f' not being in scope is the difference between 'let' and 'val' bindings in classes. To access a 'val' binding you need to prefix it with the 'this' pointer.

'let' bindings however, are always accessible and don't need to be qualified. However, you can only use 'let' in classes with implicit constructors. (type Foo (x : int) = )...

Since you are writing an explicit constructor (new (title) as form = ...) then you should be using 'val' bindings, which you initialize with the record-initialization syntax ( { f = title } ).

I agree this is a little confusion, I'll try to write a blog post to clear this up.

By on 8/18/2008 3:59 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