问题描述
使用Binding.subModelSelectedItem()时出现以下错误:
FS0001: Type mismatch. Expecting a 'string -> Binding<(Model * 'a),b>'
but given a
'string -> Binding<Model,Msg>'.
The type 'Model * 'a' does not match the type 'Model'
通过以下F#代码:
type Msg =
| SetAppointmentKey of int option
然后,在绑定中:
"SelectedAppointmentKey" |> Binding.subModelSelectedItem("AppointmentKeys",(fun m -> m.SelectedAppointmentKey),SetAppointmentKey)
我不明白该错误信息。错误消息是什么意思? “期待”来自谁?从什么中“给出”?
很抱歉,我的无知,但是这位新手没有尝试解决此问题。
谢谢您的帮助。
TIA
解决方法
我不确定您的代码中的特定错误在哪里,但是我可以尝试帮助您了解错误消息的含义。一个简单的例子来说明相同的错误:
let foo (f:int -> int) = ()
let bar x = ""
foo bar
这不起作用,因为foo
需要一个函数int -> int
,但是bar
返回一个string
。您会得到:
错误FS0001:类型不匹配。期望
不匹配int -> int
但给定了int -> string
类型int
与类型string
该错误消息告诉您,用作参数的函数的类型错误。它会告诉您这两种类型以及错误的一部分(此处返回类型不匹配)。
查看您的错误消息:
FS0001:类型不匹配。期待
不匹配string -> Binding<(Model * 'a),'b>
但给了string -> Binding<Model,Msg>
。 类型Model * 'a
与类型Model
似乎您正在某处创建一个函数,该函数需要一个字符串并返回一个Binding
。预期该函数将返回以Binding
作为第一个类型参数的Model
,但是您的代码将返回由Model
和其他东西组成的元组。
如果您的代码中包含fun x -> ...,something
,那么可能很容易发生这种事情,也许是在您想要(fun x -> ...),something
的地方。如果您写了类似的错误消息,例如:
let foo (f:int -> int) = ()
let bar = fun x -> 0,1
foo bar