【发布时间】:2012-01-15 12:44:50
【问题描述】:
给定以下代码:
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 参数在函数中保持通用?
【问题讨论】:
标签: f# value-restriction