haskell-pipes

Running a consumer inside a pipe

六眼飞鱼酱① 提交于 2019-12-10 17:38:32
问题 I need to compose a consumer and a pipe so that the output of the consumer would feed the input of the pipe. I guess this could be solved with a combinator like this: Consumer i m r -> (r -> Producer o m r') -> Pipe i o m r' or this: Consumer i m i' -> Pipe i' o m r -> Pipe i o m r or a lifting function like the following: Consumer i m r -> Pipe i o m r or like this: Consumer i m o -> Pipe i o m r I tried doing consumer >~ pipe without a success. So how to approach this? 回答1: Something

Construct a pipes Proxy inside-out

放肆的年华 提交于 2019-12-10 09:54:46
问题 Is it possible to make a function so that a Proxy from pipes can be constructed inside-out? By inside-out, I mean create a proxy from a function that connects the upstream and downstream connections. The most desirable (but impossible) signature would be makeProxy :: (Monad m) => (Server a' a m r -> Client b' b m r -> Effect m r) -> Proxy a' a b' b m r The first problem we encounter is the mechanical problem of constructing the Proxy . There's no way for us to know if the function looks at

Space leak in Pipes with RWST

人盡茶涼 提交于 2019-12-08 16:41:20
问题 A memory analysis of the following program shows that the noleak functions runs in constant memory while the leak function leaks memory in a linear fashion. dflemstr indicated that this might be due to RWST causing an infinite chain of allocations. Is this the case and what other solutions exists? I actually dont need the Writer monad. Environment: GHC 7.8.3 on ARCH 64 bit ghc Pipe.hs -o Pipe -prof import Control.Concurrent (threadDelay) import Control.Monad (forever) import Pipes import

How do you save a file using Conduit?

落花浮王杯 提交于 2019-12-07 23:01:48
问题 How do you save a file using conduit's library? I looked through conduit's tutorial but can't seem to find anything, here is my use case: main :: IO () main = do xxs <- lines <$> (readFile filePath) sourceList xxs =$ pipe $$ saveFile pipe :: Monad m => Conduit String m String pipe = undefined So there's two question here: Does it make sense to use lines to convert a string into a list of strings and then feeding it to sourceList ? How should I implement the saveFile function so that when the

How do you save a file using Conduit?

拥有回忆 提交于 2019-12-06 12:05:50
How do you save a file using conduit's library? I looked through conduit's tutorial but can't seem to find anything, here is my use case: main :: IO () main = do xxs <- lines <$> (readFile filePath) sourceList xxs =$ pipe $$ saveFile pipe :: Monad m => Conduit String m String pipe = undefined So there's two question here: Does it make sense to use lines to convert a string into a list of strings and then feeding it to sourceList ? How should I implement the saveFile function so that when the strings xxs are fully processed, I can write it to disk? A small minimal example of what you are trying

Join two consumers into a single consumer that returns multiple values?

时间秒杀一切 提交于 2019-12-06 06:11:14
问题 I have been experimenting with the new pipes-http package and I had a thought. I have two parsers for a web page, one that returns line items and another a number from elsewhere in the page. When I grab the page, it'd be nice to string these parsers together and get their results at the same time from the same bytestring producer, rather than fetching the page twice or fetching all the html into memory and parsing it twice. In other words, say you have two Consumers: c1 :: Consumer a m r1 c2

Haskell Pipes - get return value of last Proxy in pipeline

不问归期 提交于 2019-12-06 04:35:56
问题 Let's say I have two Proxy in Haskell Pipes. They represent external system processes. produce :: MonadIO m => Producer ByteString m ExitCode consume :: MonadIO m => Consumer ByteString m ExitCode So I hook them into an Effect , like this: effect :: Effect m ExitCode effect = produce >-> consume This Effect is going to give me the ExitCode from the first Proxy that terminates. Ordinarily this will be the produce , not the consume . What's the idiomatic Pipes way to get the return value of the

using haskell pipes-bytestring to iterate a file by line

こ雲淡風輕ζ 提交于 2019-12-06 03:37:40
问题 I am using the pipes library and need to convert a ByteString stream to a stream of lines (i.e. String ), using ASCII encoding. I am aware that there are other libraries (Pipes.Text and Pipes.Prelude) that perhaps let me yield lines from a text file more easily, but because of some other code I need to be able to get lines as String from a Producer of ByteString . More formally, I need to convert a Producer ByteString IO () to a Producer String IO () , which yields lines. I am sure this must

Construct a pipes Proxy inside-out

故事扮演 提交于 2019-12-05 18:56:53
Is it possible to make a function so that a Proxy from pipes can be constructed inside-out? By inside-out, I mean create a proxy from a function that connects the upstream and downstream connections. The most desirable (but impossible) signature would be makeProxy :: (Monad m) => (Server a' a m r -> Client b' b m r -> Effect m r) -> Proxy a' a b' b m r The first problem we encounter is the mechanical problem of constructing the Proxy . There's no way for us to know if the function looks at the Server or Client except by having each of them be M , in which case we'll only know which one it

why pipes defines inner functions

試著忘記壹切 提交于 2019-12-05 12:47:45
I'm looking at the pipes library source code and for instance in the Core module I don't understand why the author is all over the place using the pattern of defining functions like that: runEffect = go where go p = ... Or: pull = go where go a' = ... Or: reflect = go where go p = ... Is this some trick to enable some optimizations? I find it ugly, if it's some optimization trick I really wish the compiler could do it without things like that. But maybe there's another reason? GHC will only inline non-recursive functions, and only when they are "fully applied" from a syntactic point of view (i