這是在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