Skip to content

Multiple Simultaneous Events (Issue #25)

HeinrichApfelmus edited this page Mar 23, 2012 · 3 revisions

Discussion

Main discussion thread: https://github.com/HeinrichApfelmus/reactive-banana/issues/25

The main reason for disallowing multiple simultaneous events is the intricate interaction with accumE and apply. See this comment.

Conclusion

The compromise that is going to be implemented is

  1. Add a function

     unionWith :: (a -> a -> a) -> Event a -> Event a -> Event a
     unionWith f e1 e2 = foldr1 f <$> collect (e1 `union` e2)
    

    Example

     unionWith (+) [ [1,2], [3] ] [ [4], [] ] = [ [7], [3] ]
    
  2. Remove general Monoid instance for Event. Introduce Monoid instance

     instance Monoid (Event (a -> a)) where
         mempty  = never
         mappend = unionWith (flip (.)) 
    
  3. Provide a different type (proposed name CalmEvent) in a specialized module that offers the guarantee that it contains only one event at each point in time. Not sure yet whether to implemented it on top of the current semantics or as alternate semantics.

    See also https://github.com/HeinrichApfelmus/reactive-banana/issues/26.