[英]F# Async problem
我已经在F#中编写了一个虚拟的http服务器作为练习。
我正在使用MonoDevelop在Ubuntu 10.04 x86_64上使用Mono 2.4.4。
以下代码无法编译并显示错误:
Error FS0039: The field, constructor or member 'Spawn' is not defined (FS0039)
有人可以在Visual Studio中尝试这个吗,我不知道这是Mono问题还是我的问题。
我已经尝试了F#书中的几个Async示例,它们还都产生有关Async。*方法的类似消息。
谢谢,
克里斯。
#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
现在称为Start
(自几年前出版了几本书以来,库的API有所更改)。
在以下位置查看文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.