Elm 将多个信号传递给Signal.map会引发类型不匹配错误

Elm 将多个信号传递给Signal.map会引发类型不匹配错误,elm,Elm,我正在尝试使用elm-0.15打印鼠标光标与窗口中心的距离。例如,将光标放置在窗口中心必须打印(0,0) 我的密码是 import Graphics.Element exposing (show) import Mouse import Signal import Window relativeMouse : (Int, Int) -> (Int, Int) relativeMouse (ox, oy) (x,y) = (x - ox, y - oy) center: (Int, In

我正在尝试使用elm-0.15打印鼠标光标与窗口中心的距离。例如,将光标放置在窗口中心必须打印(0,0)

我的密码是

import Graphics.Element exposing (show)
import Mouse
import Signal
import Window

relativeMouse : (Int, Int) -> (Int, Int)
relativeMouse (ox, oy) (x,y) = (x - ox, y - oy)

center: (Int, Int) -> (Int, Int)
center (w,h) = (w/2, h/2)

main = Signal.map show <| relativeMouse (Signal.map center Window.dimensions Mouse.position)
导入图形。元素公开(显示)
导入鼠标
输入信号
导入窗口
相对用法:(Int,Int)->(Int,Int)
相对熵(ox,oy)(x,y)=(x-ox,y-oy)
中心:(Int,Int)->(Int,Int)
中心(w,h)=(w/2,h/2)

main=Signal.map show注释是您所做的更改:

import Graphics.Element exposing (show)
import Mouse
import Signal
import Window

-- change type signature to match implementation
relativeMouse : (Int, Int) -> (Int, Int) -> (Int, Int)
relativeMouse (ox, oy) (x,y) = (x - ox, y - oy)

-- use // for integer division
center: (Int, Int) -> (Int, Int)
center (w, h) = (w // 2, h // 2)

-- 1) map center over Window.dimensions to get a signal of origin positions
-- 2) map2 relativeMouse over the signal of origin positions and
--    Mouse.position to get signal of relative mouse positions
-- 3) map show over the signal of relative mouse positions to display them
main = Signal.map show (Signal.map2 relativeMouse (Signal.map center Window.dimensions) Mouse.position)
回答最后一个问题:
Signal.map2
是将1个函数映射到2个信号上的函数。对应的地图存在于
map5
之前

信号输入线也可以更改为

import Signal exposing ((<~), (~))

import Signal exposing((注释是您所做的更改:

import Graphics.Element exposing (show)
import Mouse
import Signal
import Window

-- change type signature to match implementation
relativeMouse : (Int, Int) -> (Int, Int) -> (Int, Int)
relativeMouse (ox, oy) (x,y) = (x - ox, y - oy)

-- use // for integer division
center: (Int, Int) -> (Int, Int)
center (w, h) = (w // 2, h // 2)

-- 1) map center over Window.dimensions to get a signal of origin positions
-- 2) map2 relativeMouse over the signal of origin positions and
--    Mouse.position to get signal of relative mouse positions
-- 3) map show over the signal of relative mouse positions to display them
main = Signal.map show (Signal.map2 relativeMouse (Signal.map center Window.dimensions) Mouse.position)
回答最后一个问题:
Signal.map2
是将1个函数映射到2个信号上的函数。对应的映射存在于
map5

信号输入线也可以更改为

import Signal exposing ((<~), (~))

import Signal exposing((注释是您所做的更改:

import Graphics.Element exposing (show)
import Mouse
import Signal
import Window

-- change type signature to match implementation
relativeMouse : (Int, Int) -> (Int, Int) -> (Int, Int)
relativeMouse (ox, oy) (x,y) = (x - ox, y - oy)

-- use // for integer division
center: (Int, Int) -> (Int, Int)
center (w, h) = (w // 2, h // 2)

-- 1) map center over Window.dimensions to get a signal of origin positions
-- 2) map2 relativeMouse over the signal of origin positions and
--    Mouse.position to get signal of relative mouse positions
-- 3) map show over the signal of relative mouse positions to display them
main = Signal.map show (Signal.map2 relativeMouse (Signal.map center Window.dimensions) Mouse.position)
回答最后一个问题:
Signal.map2
是将1个函数映射到2个信号上的函数。对应的映射存在于
map5

信号输入线也可以更改为

import Signal exposing ((<~), (~))

import Signal exposing((注释是您所做的更改:

import Graphics.Element exposing (show)
import Mouse
import Signal
import Window

-- change type signature to match implementation
relativeMouse : (Int, Int) -> (Int, Int) -> (Int, Int)
relativeMouse (ox, oy) (x,y) = (x - ox, y - oy)

-- use // for integer division
center: (Int, Int) -> (Int, Int)
center (w, h) = (w // 2, h // 2)

-- 1) map center over Window.dimensions to get a signal of origin positions
-- 2) map2 relativeMouse over the signal of origin positions and
--    Mouse.position to get signal of relative mouse positions
-- 3) map show over the signal of relative mouse positions to display them
main = Signal.map show (Signal.map2 relativeMouse (Signal.map center Window.dimensions) Mouse.position)
回答最后一个问题:
Signal.map2
是将1个函数映射到2个信号上的函数。对应的映射存在于
map5

信号输入线也可以更改为

import Signal exposing ((<~), (~))
导入信号((