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