问题标签 [haskell-pipes]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
101 浏览

haskell - Converting StateT IO monad to use Control.Proxy - which is Server and which is Client?

I am implementing a game engine. Most of my code currently resides in a StateT Game IO () monad. I use IO to get user input, and in fact all IO channels through one function,

which prompts the user with all presented options, reads in a response, and returns it. For a particular flow of user responses (and initial state), the game proceeds deterministically, and I'd like to factor out these user responses to help with testing.

When I try to convert this to use Pipes, what feels most similar is to change all my code which is currently in StateT Game IO (), and make it run in Proxy p, Monad m => Client p [String] String m (). This way I can still 'request' choices from the user, which allows me to write the engine code in a blocking style, assuming that user choices will be provided as I need them.

However, this seems wrong - surely the user should be the Client, and the game engine the Server? What principles can I use to make this distinction correctly?

0 投票
2 回答
210 浏览

haskell - How can I have a pipe with multiple communication types?

Say I have this code:

Currently the client always sends Int, and receives Bool. However, I want the client to also be able to query for the highest value that the server has seen so far. So I also need communication of sending () and receiving Int. I could encode this as the client sending Either Int (), and receiving Either Bool Int. However, I'd like to ensure that the two aren't mixed - sending an Int always gets a Bool response.

How can this be done?

0 投票
1 回答
167 浏览

haskell - 我可以让 Control.Proxy 中的 StateP 成为 MonadState 的一个实例吗?

我正在将一些曾经在StateTmonad 中运行的代码更改为在StatePfrom中运行Control.Proxy。但是,我的一些代码(例如%=from 的运算符Control.Lens)需要一个MonadState实例。只添加这样一个实例对我来说是否安全/正确?这似乎是由库最正确处理的东西(在这种情况下,Control.Proxy)。

0 投票
1 回答
165 浏览

haskell - Haskell Control.Proxy.TCP 生产者

我一直在使用 Control.Proxy.TCP 库,并想从网络源创建一个生产者。

上面的代码没有类型检查:

我看到 nsocketReadS 和 socketWriteD 的基本单子是 IO ,而我需要不同的类型。我该如何纠正这个问题?

0 投票
1 回答
266 浏览

haskell - 使用 Pipes 的简单程序挂起

我有以下程序,它在运行时不产生任何输出runhaskell Toy.hs,而是无限期挂起。据我了解,程序应该打印“hi”然后退出。我将不胜感激有关如何调试此类问题的答案和/或建议。我正在使用 github ( github.com/Gabriel439/Haskell-Pipes-Library ) 的 Pipes 4.0.0。

0 投票
1 回答
211 浏览

haskell - 具有动态请求/响应类型的管道?

这似乎是一件合理的事情,但我遇到了类型问题。我想要一个Client可以向 a 发送选项列表的 a Server,它将选择一个并返回所选元素。所以是这样的:

这个想法是服务器可以a -> String在列表的每个元素上调用该函数以将它们显示给用户。只要列表和函数匹配,我希望能够改变 a。

这样的事情可能吗?也许我想要的约束可以以某种方式编码到 GADT 中?

0 投票
1 回答
192 浏览

haskell - ProxyFast/ProxyCorrect 的 MonadTransControl 实例

使用管道,我正在尝试为ProxyFastProxyCorrect类型编写MonadTransControl实例。这就是我所拥有的:

我不知道如何编写liftWith 或restoreT。其他单子转换器的实例都使用“交换”单子的函数,例如 EitherT ema -> m (EitherT e Identity a),但我在管道中找不到任何这样的函数。ProxyCorrect / ProxyFast 的 MonadTransControl 实例如何?还是不能写一个?(如果是,是否可以在管道 4.0 中使用?)

0 投票
3 回答
1046 浏览

haskell - 具有下游状态且无损失的惯用双向管道

假设我有简单的生产者/消费者模型,消费者希望将一些状态传回给生产者。例如,让下游流动的对象是我们想要写入文件的对象,上游对象是一些表示对象在文件中写入位置的标记(例如偏移量)。

这两个过程可能看起来像这样(带pipes-4.0),

尽管这可能很简单,但我在推理如何组合它们时遇到了相当大的困难。理想情况下,我们需要一个基于推送的控制流,如下所示,

  1. writeObjects从阻塞开始request,发送初始ObjId 0上游。
  2. produceObjects将第一个对象 , 发送到Obj 0下游
  3. writeObjects写入对象并增加其状态,然后等待request,这次发送ObjId 1上游
  4. respond作为produceObjects回报ObjId 0
  5. produceObjects对第二个对象在步骤 (2) 继续,Obj 1

我最初的尝试是使用基于推送的组合,如下所示,

请注意使用const来解决其他不兼容的类型(这可能是问题所在)。然而,在这种情况下,我们发现它ObjId 0被吃掉了,

基于拉动的方法,

遇到类似的问题,这次 drop Obj 0

一个人如何以所需的方式创作这些作品?

0 投票
2 回答
157 浏览

haskell - 是否可以使用一次等待一次的受限管道?

我正在使用管道 4.0.0。在该库中,管道向下游产生的产量数量通常与来自上游的等待数量无关。

但是假设我想构建一个受限管道,强制为每个等待执行一个且只有一个 yield,同时仍然能够使用 monadic (>>=) 对这些类型的管道进行排序。

我观察到,在双向情况下,代理从上游请求的每个值都与发回的值匹配。所以也许我正在寻找的是一个类型函数,Proxy a' a () b m r -> Pipe a (Either b a') m r它“反映”上游的值,将它们转化为下游的额外收益。或者,不那么普遍,Client a' a -> Pipe a a'. 这样的功能可能吗?

0 投票
2 回答
586 浏览

haskell - 使用管道 4.0 折叠流的子集

我正在尝试了解管道 4.0,并想转换一些管道代码。假设我有一个Ints 流,我想跳过前五个,然后得到以下 5 个的总和。使用普通列表,这将是:

在管道中,这将是:

或者作为一个完整的程序:

但是,我不太确定如何使用管道执行此操作。