FRP frameworks and IO
Asked Answered
H

1

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?

Hypaethral answered 25/10, 2014 at 7:4 Comment(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.Misfit
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 mHypaethral
M
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.

Monkish answered 26/10, 2014 at 18:13 Comment(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...Hypaethral
Well, you can always use liftIO when you invoke an event with fire, if that's what you mean.Monkish

© 2022 - 2024 — McMap. All rights reserved.