From an Elm newbie but long-time Haskeller, a quick query.
The aim: There is a map with towns on it at designated positions on it, and I want to check if the user click is close to a town, and identify that town.
so, I collect the signal as usual:
clickPositionsSignal = sampleOn Mouse.clicks Mouse.position
that gives me a Tuple, which I want to turn into an Int (denoting the number of the nearest town). Towns are designated as
positions : [Position]
type Position = {number : Int, x : Int, y : Int}
the function to do this is:
whichTown : (Int,Int) -> Int
whichTown (x,y) =
let pz = map (\p -> getDistance p.x p.y x y) positions |> head
in pz.number
Now, I need to apply this function to my clickPositionsSignal.
Looking around various examples, I modified some code to....
whichLocationSignal : Signal Int
whichLocationSignal =
let wbl (x,y) = whichTown(x,y)
in wbl <~ clickPositionsSignal
.... and this works. I get the number of the nearest town.
But this is hopelessly cumbersome and duplicative. The question is why can I not simply write:
whichLocationSignal = whichTown clickPositionsSignal
That line throws up multiple Type Errors which I am not yet experienced enough to interpret
whichBoardPositionfunction look like? - rzetterbergwhichTown <$> clickPositionsSignalin Haskell ifSignalwas aFunctor. - rzetterberg