Skip to content

Instantly share code, notes, and snippets.

@blitzrk
Created January 6, 2016 14:39
Show Gist options
  • Save blitzrk/5029323a194a44de8b49 to your computer and use it in GitHub Desktop.
Save blitzrk/5029323a194a44de8b49 to your computer and use it in GitHub Desktop.
Code compiles, but the circular dependency of the two signals causes foldp to receive an 'undefined' input signal in the JS. Should be a compilation error.
import Graphics.Element exposing (show, Element)
import Mouse
-- VIEW
main : Signal Element
main =
Signal.map view model
view : Model -> Element
view model =
show model
-- UPDATE
update : Input -> Model -> Model
update {prev, position} model =
if prev == model
then position :: model
else model
-- MODEL
type alias Model = List Int
model : Signal Model
model =
Signal.foldp update [] input
-- SIGNALS
type alias Input =
{ prev : Model
, position : (Int, Int)
}
input : Signal Input
input =
Signal.sampleOn Mouse.clicks <|
Signal.map2 Input
model
Mouse.position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment