purescript-behaviors-demo
purescript-behaviors-demo copied to clipboard
elaborate on meaning of Behavior wraps a sampling function
i want to understand Behavior and sample and Event
Is Mouse position a nice place to start? But I don't understand the definition of position
. For example, what is the sampling function to get from a Event (Maybe Int Int) -> b0
to a Behavior
, and why?
behavior :: forall event a. (forall b. event (a -> b) -> event b) -> ABehavior event a
behavior = ABehavior
position :: Behavior (Maybe { x :: Int, y :: Int })
position = behavior \e -> map (\{ value, pos } -> value (toMaybe pos)) (withPosition ?_ )
Hole '_' has the inferred type
Event
(Maybe
{ x :: Int
, y :: Int
}
-> b0
)
You could substitute the hole with one of these values:
e