10

I've just been investigating FRP in Haskell (mainly reactive-banana (testimonials!)), and I'm wondering is it common for them, and in case of reactive-banana what's the reason to operate in IO monad instead of being constrained to MonadIO, or rven better, any Monad (so that I could provide own stack)?

It seems to me that's because of focus on GUI programming, where you integrate it with some existing libraries that operate in IO? Would it be feasible to change it so that I could integrate it with custom monad stack?

2
  • Good question, I also wondered about why reactive-banana made this decision. Did you take a look at Yampa, they took a different path.
    – martingw
    Oct 25, 2014 at 20:48
  • Nope, not yet. I'm now wondering if I could just brute-force my way through reactive-banana sourcecode and change every IO to MonadIO m
    – Bartosz
    Oct 26, 2014 at 11:36

1 Answer 1

4

If you are asking why

reactimate :: Frameworks t => Event t (IO ()) -> Moment t ()

expects an event with values of type IO () instead of allowing for a custom monad M () with instance MonadIO M, then the answer is this:

In practice, custom monad stacks only add state/reader/writer effects to the base IO monad. However, in theory, it is entirely possible to add fancy control mechanism like coroutines or non-determinism. I don't know how to integrate the internal state arising from combinators accumE with these more general effects, and I have no idea what it means for an event to happen in a non-deterministic context. That's why reactimate is restricted to IO.

If you have a custom monad stack that is of the state/reader/writer family, then it is usually possible to map it to a pure IO computation and use this with reactimate. If you find that this doesn't work out (I do think that there might be a problem), I would need a more detailed description of the concrete situation to be able to help.

2
  • Well, my reasoning was such that if you (following the slot machine example) invoke the event using fire function which just returns an IO action (and handlers are thus IO actions as well), then it should be possible to do it with other monads. I obviously have no idea about details, so this was just my hunch...
    – Bartosz
    Oct 27, 2014 at 8:19
  • Well, you can always use liftIO when you invoke an event with fire, if that's what you mean. Oct 27, 2014 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.