首先,我想指出我可以用不正确的方式翻译错误信息......这个错误是什么?我该如何编写代码?
[EntryPoint]
let Main (args:string[]) =
let start = startServer (args.[0])
Console.Read()
我不明白我该怎么做才能让编译器满意。以下代码段是否正确?
let rec handle =
let handler = socket.Accept()
let rec recieveData =
let bytesRec = handler.Receive(bytes)
let data = Encoding.ASCII.GetString(bytes,0,bytesRec)
Console.WriteLine( "Text received : {0}", data)
Console.Read()
0
答案 0 :(得分:1)
[<EntryPoint>]
let Main (args : string[]) =
let start = startServer args.[0]
Console.Read()
答案 1 :(得分:1)
我无法分辨你的代码应该做什么,因为它有外部依赖性,但至少你的问题是缩进:F#中的空格是重要的,特别是在确定词法范围方面起着重要作用。所以对于初学者你需要修复缩进,比如
[EntryPoint]
let Main (args:string[]) =
let start = startServer (args.[0])
Console.Read()
let rec handle =
let handler = socket.Accept()
let rec recieveData =
let bytesRec = handler.Receive(bytes)
let data = Encoding.ASCII.GetString(bytes,0,bytesRec)
Console.WriteLine( "Text received : {0}", data)
Console.Read()
0
此外,如果不正确,您的rec
值的使用似乎是不必要的。奇怪的是,你在handle
let表达式的主体中执行大量工作只是为了将它绑定到0
...你的意思是handle
或recieveData
来是功能?如果是这样,你可能想要更像
let handle socket = //make handle a function with socket an explicit dependency
let handler = socket.Accept()
let bytesRec = handler.Receive(bytes)
let data = Encoding.ASCII.GetString(bytes,0,bytesRec)
Console.WriteLine( "Text received : {0}", data)
Console.Read() |> ignore //probably you are using Read to wait for user interaction to continue, but just ignore the result (returning unit) instead of returning 0