我真的希望我没有在这里走入死胡同。我有一个行为,它给出当前选定的颜色和当前鼠标坐标,然后在单击鼠标时执行任务。该任务涉及查看一个列表,然后更新该列表中的值,以便稍后检索它。我可以“存储”所选颜色的事实让我希望可以以类似的方式存储列表。我只是在死胡同,不知道如何解决这个问题。非常感谢一些帮助。
-- There is a Blue button and a Red button on our UI. Whichever
-- button was clicked last is our current color selection.
colorRedSelected = const ColorRed <$ UI.click redButton
colorBlueSelected = const ColorBlue <$ UI.click blueButton
-- we combine both the above Events to create a new one that tells us the current selected color
colorSelected = unionWith const colorRedSelected colorBlueSelected
-- accumulate values for our Behaviour, starting with ColorRed selected by default
colorMode <- accumB ColorRed modeEvent
-- create a Behaviour
mouseCoordinate <- stepper (0,0) $ UI.mousemove canvas
-- want to start with the list [1,2,3,4], but this value should change later.
-- I have 'never' here, as I don't know what else to put here yet.
listState <- accumB ([1,2,3,4]) never
-- Combine the Behaviours, we now have a tuple (chosenColorMode, mouseCoordinateTuple, savedList)
let choices = (,,) <$> colorMode <*> mouseCoordinate <*> listState
-- Apply the event (of the user clicking the canvas) to the Behaviour,
-- creating a new Event that returns the above tuple when it fires
makeChoice = choices <@ UI.click canvas
onEvent makeChoice $ \(colorMode, (x,y), savedList) -> do
...
-- in this block we use the savedList, and generate a newList.
-- I want to update the choicePosition behaviour so that the newList
-- replaces the old savedList.