type Point2D( x : float, y : float ) =

member t.X = x

member t.Y = y

What is the t doing in this declaration??

Is it sort of interesting to note that it is only really interesting if you need to refer to some other member of the class in your initializer. For example, this would be a case where you care about the name of the class specifier:

1
2
3
4
5
6
type MyOddPoint2D(x:float, y:float) =

    member t.X  = x * 2.0

    member t.Y = t.X + y;;

In that case the t is just a place holder for the name of the current class--has to match on both sides of the assignment. You could change the third line to

1
member thisClass.Y = thisClass.X + y

and it works equally well. It'd be confusing for anyone maintaining your code but as far as I can tell the compiler doesn't care.

Hope my meaning is clear--I'm not sure how well I'm communicating myself.

By on 5/7/2010 10:02 PM ()
By on 5/7/2010 12:44 PM ()

t is an identifier representing the object on which you're calling the method. This corresponds to "this" in C#, for instance, but in F# you can choose to call it whatever you'd like (and even use different identifiers for different members).

By on 5/7/2010 12:22 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