Depending on the return type, Signal (Int, Int) is not recognised as a tuple of (Int, Int).
Consider the following code:
import Graphics.Element exposing (..)
import Mouse
relativeMouseElement : (Int, Int) -> Element
relativeMouseElement mp = show (fst mp - 1000, snd mp - 1000)
relativeMouseTuple : (Int, Int) -> (Int, Int)
relativeMouseTuple mp = (fst mp - 1000, snd mp - 1000)
main =
-- Signal.map relativeMouse Mouse.position
relativeMouseTuple Mouse.position
Signal.map relativeMouse Mouse.position
works just fine, displays (-1000, -1000) to the browser and the values are adjusted according to the mouse movement.
relativeMouseTuple Mouse.position
This though does not work. The complication error I get is the following:
Function `relativeMouseTuple` is expecting the argument to be:
( Int, Int )
But it is:
Signal ( Int, Int )
I find this very weird. In both case the first argument is Signal (Int, Int) and in the second case it results to a type error.
Any ideas?
I have no experience with elm AT ALL, however:
Signal.map
maps a function to a signal, this doesn't mean that the function is called with the Signal
as a parameter, but that it is called with the signal's arguments as parameter. e.g. for Signal(Int, Int)
you map a function that receives (Int, Int)
as arguments.
So in the following case you have no problem
Signal.map relativeMouse Mouse.position
However, in the case below, you call a function that expects (Int, Int)
with the argument Signal(Int, Int)
which is wrong:
relativeMouseTuple Mouse.position
What you should do, is probably map your function to the Signal like this:
Signal.map relativeMouseTuple Mouse.position