【问题标题】:Display Signal Value with Other Text用其他文本显示信号值
【发布时间】:2014-12-17 02:19:11
【问题描述】:

我刚开始学习榆树。在这个程序中,我想用一些输出格式的鼠标坐标和箭头键状态来更新屏幕。

我的计划是创建一个名为 Input 的记录,并使用 Signals by function input 设置该记录。然后 showGameInputs 将使用 Input 记录来获取值并将它们与一些文本组合以将元素返回给 main。

import Mouse
import Keyboard
-- Create a record named Input
type Input = { mouseX:Int, mouseY:Int, arrowUpdown:Int, arrowLeftRight:Int }

-- Combine Signals into Input type
input: Signal Input
input = Input <~ Mouse.x ~ Mouse.y ~ lift .y Keyboard.arrows ~ lift .x Keyboard.arrows

showGameInputs: Input -> Element
showGameInputs { mouseX, mouseY, arrowUpdown, arrowLeftRight } = plainText ("asdf" ++ show mouseX)


main: Signal Element
main = showGameInputs input

这是错误:

[1 of 1] 编译 Main ( Functions.elm ) 在第 19 行第 23 到 28 列输入错误: 输入

预期类型:信号输入 实际类型:输入

对 Elm 和函数式编程非常陌生,所以我怀疑我在这里遗漏了一些基本的东西。

感谢您的帮助。

【问题讨论】:

    标签: elm


    【解决方案1】:

    你快到了。错误消息的格式有点混乱(一个已知问题),但它说input 实际上应该是Input 的类型。之所以这么说是因为您在input: Signal Input 上应用showGameInputs: Input -&gt; Element。您只需将main 更改为:

    main = showGameInputs <~ input
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-04
      • 1970-01-01
      相关资源
      最近更新 更多