Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
转换F#函数a b->;c到c#Func<;a、 b,->;c<;布尔>&燃气轮机;_C#_F#_Embedio - Fatal编程技术网

转换F#函数a b->;c到c#Func<;a、 b,->;c<;布尔>&燃气轮机;

转换F#函数a b->;c到c#Func<;a、 b,->;c<;布尔>&燃气轮机;,c#,f#,embedio,C#,F#,Embedio,在C#中: 现在我需要调用 let HandleRequest (context:HttpListenerContext, ct:CancellationToken) = Task.FromResult(false) //or let HandleRequest (context:HttpListenerContext) (ct:CancellationToken) = Task.FromResult(false) 让toFunc f= 系统功能 键入FunApi()如下所示=

在C#中:

现在我需要调用

let HandleRequest (context:HttpListenerContext, ct:CancellationToken) =
    Task.FromResult(false)
//or
let HandleRequest (context:HttpListenerContext) (ct:CancellationToken) =
    Task.FromResult(false)
让toFunc f=
系统功能
键入FunApi()如下所示=
继承WebModuleBase()
做
让handle=HandleRequest |>toFunc
this.AddHandler(ModuleMap.AnyPath,HttpVerbs.Any,handle)
但我得到了一个错误:

let toFunc<'I, 'T> f =
        System.Func<'I,'T> f

type FunApi() as this =
  inherit WebModuleBase()

  do
      let handle = HandleRequest |> toFunc
      this.AddHandler(ModuleMap.AnyPath, HttpVerbs.Any, handle)
/../Data.fs(57,57):错误FS0001:此表达式应具有类型
“Func”但这里有类型
“Func”(FS0001)

函数需要三个参数,因为它将HttpListenerContext和CancellationToken作为参数,并返回Task作为结果

/..../Data.fs(57,57): Error FS0001: This expression was expected to have type    
'Func<HttpListenerContext,CancellationToken,Task<bool>>'    but here has type    
'Func<(HttpListenerContext * CancellationToken),Task<bool>>' (FS0001)
open System.Threading.Tasks
开放系统.Net
//或
let HandleRequest(上下文:HttpListenerContext)(ct:CancellationToken)=
printfn“%s”你好世界
Task.FromResult(false)
让toFunc f
键入FunApi()如下所示=
继承WebModuleBase()
做
让handle=HandleRequest |>toFunc
this.AddHandler(ModuleMap.AnyPath,HttpVerbs.Any,handle)
覆盖_u.Name=“BlaBla”
[]
让主参数=
使用服务器=新的Web服务器(“http://localhost:9696/")
RegisterModule(新FunApi())
server.RunAsync()|>忽略
Console.ReadLine()|>忽略
0
/..../Data.fs(57,57): Error FS0001: This expression was expected to have type    
'Func<HttpListenerContext,CancellationToken,Task<bool>>'    but here has type    
'Func<(HttpListenerContext * CancellationToken),Task<bool>>' (FS0001)
open System.Threading.Tasks
open System.Net

//or
let HandleRequest (context:HttpListenerContext) (ct:CancellationToken) =
    printfn "%s" "Hello World"
    Task.FromResult(false)

let toFunc<'a, 'b, 'c> f =
        System.Func<'a, 'b, 'c> f

type FunApi() as this =
  inherit WebModuleBase()

  do
      let handle = HandleRequest |> toFunc
      this.AddHandler(ModuleMap.AnyPath, HttpVerbs.Any, handle)

  override __.Name = "BlaBla"


[<EntryPoint>]
let main args =
    use server = new WebServer("http://localhost:9696/")
    server.RegisterModule(new FunApi())
    server.RunAsync() |> ignore
    Console.ReadLine() |> ignore
    0