给定以下代码:
let DisplayImpl logger data =
data |> Seq.iter logger
printfn ""
let Working =
DisplayImpl (printfn "%O") [1;2;3]
DisplayImpl (printfn "%O") ["a";"b";"c"]
let NotWorking display =
display (printfn "%O") [1;2;3]
display (printfn "%O") ["a";"b";"c"]
~~~ ~~~ ~~~
最后一行给出了错误:This expression was expected to have type int but here has type string
我认为以下可能有效,但它没有:
let StillNotWorking (display: ('a -> unit) -> seq<'a> -> unit) =
我的问题是,如何定义 NotWorking 函数以使 display 参数在函数中保持通用?