I've been through my books, and I've googled until I've ran out of search terms, yet I still can't find an example or answer to this problem:
The following code does not compile because the type Effect and the type Affect have not been declared at the time Entity is declared. So what I don't understand is how do to work around this.
In C++, this problem is solved via a prototype declaration in h files and then including the h file. In C# it is never an issue. So how is it resolved in F#?
#light
type Entity =
{
Name:string;
Affects:List<Affect>; //Compile error: The type Affect is not defined
Effects:List<Effect>; //Compile error: the type Effect is not defined
}
type Effect =
{
Name:string;
//A function pointer for a method that takes an Entity and returns an Entity
ApplyEffect:Entity -> Entity;
}
type Affect =
{
Name:string;
//A List of Effects that are applied by this Affect Object
EffectList:List<Effect>;
//A function pointer to return an Entity modified by the listed Effects
ApplyAffect:Entity->Entity;
}
The underlying goal here is that an object of type Entity should be able to list the Affects it can apply to objects of Type Entity. Entity can also list the Effects that have been applied to it. This way the "current" state of an entity is found by folding all of the Effects against the original entity state.
Thank you for your time,
--Adam Lenda
The force F can now be resolved into two components Fx and Fy along the x and y axes and hence, the components are called rectangular components.
A vector can be resolved into many different vectors, for resolution of vectors. For Example: Let us consider two numbers, say, 4 and 6, which is further added to obtain 10. Further, now 10 is broken or resolved. However, the number 10 can also be resolved into many other numbers like –10 = 5 + 5; 10 = 3 + 7 etc.
The formula for the resultant force vector is given by Newton's Second law. This law states that the force is equal to mass times acceleration, or F=ma.
I believe this is the correct answer:
http://langexplr.blogspot.com/2008/02/defining-mutually-recursive-classes-in.html
so...
type Entity =
{
Name:string;
Affects:List<Affect>;
Effects:List<Effect>;
}
and Effect =
{
Name:string;
ApplyEffect:Entity -> Entity;
}
and Affect =
{
Name:string;
EffectList:List<Effect>;
ApplyAffect:Entity->Entity;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With