Git Product home page Git Product logo

Comments (2)

HeinrichApfelmus avatar HeinrichApfelmus commented on June 17, 2024

The very first version of reactive-banana provided two functions with different names

union :: Event a -> Event a -> Event a
merge :: Event a -> Event b -> Event (Either a b)

Later, I have dropped the merge function because it turned out to be way less useful than union. (That's also why the MonadPlus and Alternative classes don't provide something like merge).

The reason is that its usually more convenient to apply different pattern matches right away instead of building a direct sum first and then deconstructing it again. In other words, the result of merge is usually used with a pattern match. The prototypical example

either f g (e1 `merge` e2) = (f <$> e1) `union` (g <$> e2)

shows that union is actually more convenient for this application, since it dispenses with the intermediate Either type and easily generalizes to severeal unions.

In your example, we have the special situation that the return type is ignored, i.e.

eQuit = () <$ (eWindowClose `merge` eCtrlQ `merge` eSIGINT)

and the pattern match disappears entirely, that's why it looks a bit more convenient. However, using the function

Control.Monad.void :: Functor f => f a -> f ()

you can drop the parentheses and make the whole thing a bit nicer

eQuit = void eWindowClose `union` void eCtrlQ `union` void eSIGINT

I think that this is a good compromise.

Summary

  • I'm against changing the type of union.
  • I'm don't like introducing the merge function again, because I feel that it clutters the interface.
  • I think that the void function is enough to make your example reasonably nice.

Let me know what you think.

PS: I've changed your post to read newUnion :: FRP f => Event f a -> Event f b -> Event f (Either a b) because that's what you probably meant.

from reactive-banana.

ehird avatar ehird commented on June 17, 2024

Oh, silly me; I had assumed that Control.Monad.void would only work on monads, due to the module name. Yes, I agree with your conclusion; I think this thought was a bit premature.

from reactive-banana.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.