I was fiddling around in Visual Studio and I discovered that
delegate RecursiveDelegate RecursiveDelegate();
is a valid delegate definition.
I don't have a great deal of functional programming experience, but I was wondering if this pattern is ever actually useful in functional programming, or if its just a curiosity of semantics. I want to ask this question in two ways:
It's a potentially useful pattern for a state machine:
delegate State State();
State state = MainMenu;
while (state != null) // or have a 'pump' call each update
{
state = state();
}
State MainMenu()
{
if (playPressed) return StartLevelOne();
return MainMenu;
}
State StartLevelOne()
{
//set up level
return LevelOne; // or LevelOne() if you want an immediate update
}
State LevelOne()
{
//check for level one ending
return LevelOne;
}