2 つの信号を結合する入力関数の結果で 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)`
主にrenderをasTextに置き換えて同様のエラーが発生する可能性があるため、render処理入力に問題がある可能性がありますが、foldpで使用している関数にも問題があると思います.