简体   繁体   English

FRP框架和IO

[英]FRP frameworks and IO

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)? 我刚刚在Haskell中调查FRP(主要是reactive-banana (推荐!)),我想知道它们是否常见,并且在反应性香蕉的情况下,在IO monad中操作的原因是什么,而不是受限制MonadIO ,或者更好,任何Monad (这样我可以提供自己的堆栈)?

It seems to me that's because of focus on GUI programming, where you integrate it with some existing libraries that operate in IO ? 在我看来,这是因为专注于GUI编程,你将它与一些在IO中运行的现有库集成? Would it be feasible to change it so that I could integrate it with custom monad stack? 是否可以更改它以便我可以将它与自定义monad堆栈集成?

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: 期望一个值为IO ()的事件,而不是允许使用instance MonadIO M的自定义monad M () ,那么答案是这样的:

In practice, custom monad stacks only add state/reader/writer effects to the base IO monad. 实际上,自定义monad堆栈仅将状态/读取器/写入器效果添加到基本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. 我不知道如何将组合器accumE产生的内部状态与这些更普遍的影响结合accumE ,我不知道事件在非确定性环境中发生意味着什么。 That's why reactimate is restricted to IO . 这就是为什么reactimate限制只限于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 . 如果您具有状态/读取器/写入器系列的自定义monad堆栈,则通常可以将其映射到纯IO计算并将其与reactimate使用一起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. 如果您发现这不起作用(我认为可能存在问题),我需要对具体情况进行更详细的描述才能提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM