[英]F# Async problem
I've written a dummy http server as an exercise in F#. 我已经在F#中编写了一个虚拟的http服务器作为练习。
I'm using Mono 2.4.4 on Ubuntu 10.04 x86_64, with MonoDevelop. 我正在使用MonoDevelop在Ubuntu 10.04 x86_64上使用Mono 2.4.4。
The following code fails to compile with the error: 以下代码无法编译并显示错误:
Error FS0039: The field, constructor or member 'Spawn' is not defined (FS0039)
Could someone try this in VisualStudio please, I don't know whether this is a Mono problem, or my problem. 有人可以在Visual Studio中尝试这个吗,我不知道这是Mono问题还是我的问题。
I have tried several Async examples from the F# book, and they also all produce similar messages about Async.* methods. 我已经尝试了F#书中的几个Async示例,它们还都产生有关Async。*方法的类似消息。
Thanks, 谢谢,
Chris. 克里斯。
#light
open System
open System.IO
open System.Threading
open System.Net
open System.Net.Sockets
open Microsoft.FSharp.Control.CommonExtensions
printfn "%s" "Hello World!"
let headers = System.Text.Encoding.ASCII.GetBytes("HTTP/1.0 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\nContent-Length: 37\r\nDate: Sun, 13 Jun 2010 05:30:00 GMT\r\nServer: FSC/0.0.1\r\n\r\n")
let content = System.Text.Encoding.ASCII.GetBytes("<html><body>Hello World</body></html>")
let serveAsync (client : TcpClient) =
async { let out = client.GetStream()
do! out.AsyncWrite(headers)
do! Async.Sleep 3000
do! out.AsyncWrite(content)
do out.Close()
}
let http_server (ip, port) =
let server = new TcpListener(IPAddress.Parse(ip),port)
server.Start()
while true do
let client = server.AcceptTcpClient()
printfn "new client"
Async.Spawn (serveAsync client)
http_server ("0.0.0.0", 1234)
Spawn
is now called Start
(the library APIs have changed a bit since a couple of the books were published a few years ago). Spawn
现在称为Start
(自几年前出版了几本书以来,库的API有所更改)。
Check the docs at 在以下位置查看文档
http://msdn.microsoft.com/en-us/library/ee370232.aspx http://msdn.microsoft.com/en-us/library/ee370232.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.