How do I unify two or more Signals in elerea?

Is there something like reactive-bananas union function in elerea ? union :: Signal a -> Signal a -> Signal a This just merges the two signals into one stream. Ideally I am searching for an efficient union of a large number (14k) of signals: unions :: [Signal a] -> Signal a There doesn't seem to be anything in the docs, nor is there anything that I could recognize as a building

我如何统一elerea中的两个或更多信号?

elerea有没有像reactive-bananas union功能的elerea ? union :: Signal a -> Signal a -> Signal a 这只是将两个信号合并成一个流。 理想情况下,我正在寻找大量(14k)信号的高效联合: unions :: [Signal a] -> Signal a 文档中似乎没有任何内容,也没有任何我可以认为是其构建模块的东西。 编辑:除了可能是这样的: unionSignal :: a -> Signal a -> Signal a -> SignalGen p (Signal a) unionSig

Unmask async exceptions in STM transaction

I have a function that posts a request to an STM channel and then blocks the thread waiting for that request's completion. If my blocked thread is terminated by an async exception then I want to post a cancellation request to that STM channel. It currently looks like this: runRequest channel request = mask $ restore -> do (reqId, resultVar) <- restore . atomically $ requestPostSTM

在STM事务中取消屏蔽异步异常

我有一个函数向STM通道发送请求,然后阻塞等待请求完成的线程。 如果我的阻塞线程被异步异常终止,那么我想发送取消请求到该STM通道。 它目前看起来像这样: runRequest channel request = mask $ restore -> do (reqId, resultVar) <- restore . atomically $ requestPostSTM channel request onException (restore . atomically $ do maybeResult <- readTVar resultVar case maybeResult of

friendly list as a change log

I need an advice on the data structure to use as an atomic change log. I'm trying to implement the following algorithm. There is a flow of incoming changes updating an in-memory map. In Haskell-like pseudocode it is update :: DataSet -> SomeListOf Change -> Change -> STM (DataSet, SomeListOf Change) update dataSet existingChanges newChange = do ... return (da

友好的列表作为更改日志

我需要关于数据结构的建议以用作原子更改日志。 我试图实现以下算法。 存在更新内存映射的传入更改流。 在Haskell中,它是伪代码 update :: DataSet -> SomeListOf Change -> Change -> STM (DataSet, SomeListOf Change) update dataSet existingChanges newChange = do ... return (dataSet, existingChanges ++ [newChange]) 其中DataSet是一个映射(目前它是来自stm-containers包的映射

Haskell STM alwaysSucceeds

There is a function in haskell's stm library with the following type signature: alwaysSucceeds :: STM a -> STM () From what I understand of STM in haskell, there are three ways that something can "go wrong" (using that term loosely) while an STM computation is executing: The value of an TVar that has been read is changed by another thread. An user-specified invariant is vio

Haskell STM总是会成功

Haskell的stm库中有一个函数,它具有以下类型的签名: alwaysSucceeds :: STM a -> STM () 根据我对haskell中STM的理解,在执行STM计算时,有三种方式可能“出错”(松散地使用该术语): 已经读取的TVar的值由另一个线程改变。 违反了用户指定的不变量。 这似乎通常通过调用retry来retry启动来触发。 这有效地使线程阻塞,然后在读取集中的TVar改变后重试。 抛出异常。 调用throwSTM导致这一点。 这与前两个不同,

Does reading a TChan result in blocking or polling?

First, some background. I want a queue which I would like to operate in one of two different modes. In the first mode, I want to be able retrieve an element if one exists in the queue but not to block if there is no element. In the second mode, I want to be able to block until the queue has an element. (I am aware that I could use a specialized mechanism for each mode, but I'd like to fac

阅读TChan会导致阻止还是轮询?

首先,一些背景。 我想要一个队列,我希望以两种不同模式之一进行操作。 在第一种模式下,我希望能够在队列中存在元素时检索元素,但如果没有元素则不能阻止元素。 在第二种模式下,我希望能够阻塞,直到队列中有一个元素。 (我知道我可以为每种模式使用专门的机制,但我想分解出一些常见的代码,因此如果我可以在两种操作模式中使用相同的机制,这将是最简单的。) 我可以使用Chan ,但根据文档我不应该使用isEmptyChan

Removing the contents of a Chan or MVar in a single discrete step

I'm writing a discrete simulation where request values from multiple threads accumulate in a centralized queue. Every n milliseconds, a manager wakes up to process requests. When the manager wakes up, it should retrieve all of the contents of the central queue in a single discrete step. While processing these, any client threads attempting to submit to the queue should block. When process

在单个离散步骤中移除Chan或MVar的内容

我正在编写一个离散仿真,其中来自多个线程的请求值在集中式队列中累积。 每经过n毫秒,一位经理就会醒来处理请求。 当管理者醒来时,它应该在一个离散步骤中检索中央队列的所有内容。 在处理这些请求时,任何尝试提交队列的客户端线程都应该被阻塞。 处理完成后,队列重新打开并且管理器重新进入休眠状态。 什么是最好的方法来做到这一点? STM的重试行为并不是我想要的。 如果我使用Chan或MVar,则无法阻止客户端在处

style pattern matching with type checking

I am working on a project to recreate some of the features of Haskell in Clojure. I have succeeded in implementing Hindley-Milner type inference, and now I am trying to introduce pattern-matching syntax via a macro. My goal is to have the macro first emit valid Clojure code and then type-check that code, but I am finding this hard to do. Since I'm brand new to Haskell and static typing in

样式模式匹配与类型检查

我正在开发一个项目,在Clojure中重新创建Haskell的一些功能。 我成功实现了Hindley-Milner类型推断,现在我试图通过宏引入模式匹配语法。 我的目标是先让宏发出有效的Clojure代码,然后键入检查代码,但我发现这很难做到。 由于我对Haskell和静态打字都是全新的,所以我不确定是否有办法做到这一点,我没有看到,或者它是不可能的。 我试图按照Luc Maranget的算法,至少现在是天真的版本。 我的理解是,你将一个向量值(

Functional programming : Where does the side effect actually happen?

After beginning to learn Haskell, there something I don't understand in Haskell even after reading a lot of documentation. I understand that to perform IO operation you have to use a "IO monad" that wrapped a value in a kind of "black box" so the any function that uses the IO monad is still purely functional. OK, fine, but then where does the IO operation actually happe

功能性程序设计:副作用实际发生在哪里?

在开始学习Haskell之后,即使在阅读了大量文档之后,我仍然在Haskell中不理解。 据我所知,要执行IO操作,您必须使用“IO monad”以“黑匣子”的形式包装值,以便使用IO monad的任何函数仍然是纯粹的功能。 好吧,很好,但是IO操作实际发生在哪里? 这是否意味着Monad本身并不是纯粹的功能? 或者是IO操作实现了,比方说C语言,并且在Haskell编译器中“嵌入”? 我可以使用纯粹的Haskell写或不写Monad,这可以做IO操作吗? 如

In what sense is IO monad special (if at all)?

After diving into monads I understand that they are a general concept to allow chaining computations inside some context (failing, non-determinism, state, etc) and there is no magic behind them. Still IO monad feels even if not magic, but special. you cannot escape IO monad like you can with other monads IO action can only be run by the main function IO is always at the bottom of a monad

IO monad是什么意思(如果有的话)?

在深入monads之后,我明白他们是一个通用概念,允许在某些上下文(失败,非确定性,状态等)内链接计算,并且他们背后没有魔法。 即使不是魔法,但IO monad仍然感觉很特别。 你不能像其他monad那样逃脱IO monad IO操作只能由main函数运行 IO总是处于单变压器链的底部 IO monad的实现不清楚,源代码显示了一些Haskell内部 以上几点的原因是什么? 什么让IO如此特别? 更新 :纯代码评估顺序无关紧要。 但是在做IO

Haskell libraries overview and their quality

I want to use Haskell in production. It has a lot of libraties but not all of them are stable, ready-to-use and well-developed. Some libraries with interesting conceptions have experimental status. Many libraries are still in minor versions (0.0.1 for example). Some of them just abandoned. Hackage too huge to monitor them, so I need a brief slice of the current libraries state, their prospec

Haskell库概述及其质量

我想在生产中使用Haskell。 它有很多libraties,但并不是所有的都是稳定的,随时可用和发达的。 一些有趣概念的图书馆具有实验地位。 许多库仍然是次要版本(例如0.0.1)。 其中一些人刚刚放弃。 Hackage太大,无法监控它们,所以我需要对当前库状态,它们的前景和适用性进行简要介绍。 我明白这个问题非常广泛,但这些信息对任何人都有用。 在这里,我们可以一点一点地收集信息,然后将其用于信息丰富的论文。 那么我