这是在C#示例代码:我可以在F#中的类中定义结构吗?
class exampleClass
{
struct exampleStruct
{
public int number;
}
private exampleStruct[,] e;
private enum exampleMove { Up, Down, Right, Left, Enter, Escape };
Stack<int> returnPath;
bool returntoBeg;
int numRandomMoves;
public exampleClass()
{
e = new exampleStruct[5, 5];
exampleStruct ex;
returntoBeg = false;
returnPath = new Stack<int>();
numRandomMoves = 0;
for (int y = 0; y < 5; y++)
{
for (int x = 0; x < 5; x++)
{
ex = new exampleStruct();
ex.number = 0
e[x, y] = ex;
}
}
}
}
我有一个示例代码像上面,我想将它翻译成F#。但问题是,当我使用F#创建一个类并在其中定义结构时,它显示错误并指出我无法在类类型中声明类型。任何帮助?
为什么你需要这样的功能?只是将C#逐行移植到F#? – pad 2012-02-01 07:14:01
只是想学习如何做:) – 2012-02-01 09:01:00
可能的重复:http://stackoverflow.com/questions/8948332/why-doesnt-f-support-nested-classes – kkm 2012-02-01 11:31:33