我正在尝试将 foldp 与组合两个信号的输入函数的结果一起使用。
这是我的代码。
import Graphics.Element (..)
import Graphics.Collage (..)
import Color (..)
import Signal
import Keyboard
import Text (asText)
import Time (..)
-- Display
render : (Int, Int) -> Element
render (xDiff, yDiff) = collage 200 200 [
rotate (degrees (toFloat yDiff))
(filled blue (ngon 5 (10 * toFloat xDiff))) ]
-- Combine two signals to be a pair
input = Signal.map2 (,) (fps 25) Keyboard.arrows
-- Fold past combined signals from input and pass resulting signal to render
main : Signal Element
main = Signal.map render
(Signal.foldp (\dir (upd, {x, y}) ->
(x + dir.x, y + dir.y)) (0,0) input)
-- Fold past Keyboard.arrows and pass resulting signal to render
--main : Signal Element
--main = Signal.map render
-- (Signal.foldp (\dir (x, y) ->
-- (x + dir.x, y + dir.y)) (0,0) Keyboard.arrows)
我得到的错误是:
Type mismatch between the following types on line 34, column 55 to 60:
(Float, { x : Int, y : Int })
{ a | x : Int, y : number }
It is related to the following expression:
input
Type mismatch between the following types on line 34, column 26 to 46:
{ a | x : Int, y : number }
number
Looks like something besides an Int or Float is being used as a number.
It is related to the following expression:
(x + dir.x,y + dir.y)
Type mismatch between the following types on line 34, column 26 to 46:
Int
{ a | x : number, y : number }
It is related to the following expression:
(x + dir.x,y + dir.y)`
在 main 中,我可以用 asText 替换 render 并得到类似的错误,所以我认为即使渲染处理输入可能存在问题,我认为我与 foldp 一起使用的函数也存在问题。