purescript-behaviors-demo icon indicating copy to clipboard operation
purescript-behaviors-demo copied to clipboard

elaborate on meaning of Behavior wraps a sampling function

Open danlaudk opened this issue 6 years ago • 0 comments

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 

danlaudk avatar Apr 10 '18 07:04 danlaudk