Scala 提升类型不匹配?

发布于 12-27 03:43 字数 553 浏览 3 评论 0原文

我目前正在编写一个网络应用程序,我想使用提交表单中的值,但出现类型不匹配:

类型不匹配;发现:connectfour.Board=>选项[Int] 必需:() => 我的代码

看起来像这样:

var value=0
 "name=value" #> SHtml.onSubmit(s => asInt(s).foreach(value= _)) &
 // when the form is submitted, process the variable
"type=submit" #> SHtml.onSubmitUnit(askForHumanMove)

和我的askForHumanMove 方法:

def askForHumanMove(board: connectfour.Board): Option[Int] = {
    Some(value)        
}

希望有人可以帮助我解决这种类型不匹配的问题。

谢谢你!

此致, 约翰

I am programming a webapp at the moment and I want to use a value from a submit form but get a type mismatch:

type mismatch; found : connectfour.Board=> Option[Int] required: () => Any

My code looks like this:

var value=0
 "name=value" #> SHtml.onSubmit(s => asInt(s).foreach(value= _)) &
 // when the form is submitted, process the variable
"type=submit" #> SHtml.onSubmitUnit(askForHumanMove)

and my askForHumanMove method:

def askForHumanMove(board: connectfour.Board): Option[Int] = {
    Some(value)        
}

Hope somebody can help me with this type mismatch.

Thank you!

Best regards,
John

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟酒忠诚2025-01-03 03:43:56

在我看来, onSubmitUnit 接受 () =>; Any 作为参数。但是您传递的方法被提升到函数 Board =>;选项[Int]。这些类型不兼容。

在调用 onSubmitUnit 方法时,您的范围内是否有相关的 Board 实例?如果是这样,修复方法很简单:

"type=submit" #> SHtml.onSubmitUnit( () => askForHumanMove(board) )

It looks to me that onSubmitUnit accepts a () => Any as a parameter. But you are passing a method which is being lifted into a function Board => Option[Int]. These types are not compatible.

Do you have the relevant instance of Board in scope at the point of calling the onSubmitUnit method? If so, the fix is simple:

"type=submit" #> SHtml.onSubmitUnit( () => askForHumanMove(board) )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文