base is now a keyword for accessing the base class, so you should be able just use it without the 'as base' bit.

By on 9/4/2008 1:00 AM ()

That doesn't work either. This:

let obj3 =
{ new System.Object() with
member x.ToString () = "Hello, base.ToString() = " + base.ToString() }

produces:

The namespace or module 'base' is not defined.

By on 9/4/2008 1:35 PM ()

This is addressed in an update to the F# CTP that we're putting out in the next few days to cover a couple of issues found since the release. Thanks for taking the time to report the problem.

Until then I believe using " as ``base``" can act as a workaround.

Thanks

Don

By on 9/4/2008 3:12 PM ()

Hi, I'm now using the CTP and I'm also having a bit of trouble with the

base keyword. One of my objects was inheriting from a Windows Form

and now I'm unable to pass the base as a parameter. The keyword

always seems to be demanding one of its members be used. I have no

errors with ' do base.Text <- "foo" ' in a previous line but maybe

that is just an error waiting to happen.

Here is the code snip:

type GameWindow() =
inherit Form()
let mutable width = 800
let mutable height = 600
do base.Text <- "MyGame"
do base.Size <- Size(width,height)
let game = new Game(width, height, base)

The error occurs at the final line: Unexpected symbol ')' in expression. Expected '.' or other token

I've tried casting to Form but the same error happens. Before

upgrading to the CTP, I passed base.Handle but that gave me issues with

device acquiring so I'd rather not try it again. Is there any way to

tell the compiler I only want the base and not any of its members?

By on 10/24/2008 8:32 AM ()

I haven't tried it, but can you do

1
2
3
4
5
6
type GameWindow() as this =

    ...

    let game = new Game(width, height, (this :> Form))

instead?

By on 10/24/2008 9:47 AM ()

I'm pretty sure that would work, even without the casting but I don't have access to 'this' yet. I don't have the project available right now so I can't give an example but moving instantiation of the Game class to a later point would cause a big reworking of my startup code. Just a tricky combination of immutability, OO, and input device acquiring. To make the change, I would need my objects to own null references to device types which then get instatiated at an unknown future in their lifetime and I hate using objects that way, uncertain of their validity.

I did try
(base :?> Form)

but that casting syntax was from memory and I've never really needed it in F# so far (so I don't know if the '?' is correct at all). I still got the same error.

EDIT: ahh, I see the "as this" on the original type definition. As I said, I don't have the project with me but if that works, I could see that being a solution. Thanks!

By on 10/24/2008 10:59 AM ()

No dice. Compiler gave me a warning that recursive references in a type definition would be handled at runtime with a delayed reference to the object being defined. A test run still exploded.

EDIT: actually it did work, once I followed the warning's advice of moving the reference into a 'do' at the end of my declarations. I still had to use an Unchecked object but I didn't have to move anything to a member call. Thanks so much!

By on 10/24/2008 9:29 PM ()

Ah, sorry to steer you wrong. Here's something that will work, I am still trying to decide if there is a better way...

1
2
3
4
5
6
type GameWindow() as this =
    ...
    let mutable game = Unchecked.defaultof<Game>
    ...
    do game <- new Game(width, height, (this :> Form))
By on 10/25/2008 12:17 AM ()

Serves me right for leaving my edit window open too long and letting you post in ahead of me. Your suggestion did work and I ended with the same syntax you used there, I just didn't tell you in time. Thanks again, I was worried I would have to revert (and lose those fancy new project settings).

By on 10/25/2008 12:44 AM ()

BTW I just saw the title of this thread - nice one :-)

By on 9/4/2008 3:14 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