Roman Leshchinskiy wrote:
On 16/05/2010, at 11:54, Mark Wassell wrote:

Hi,

This possibly might go against the spirit of what Stream programming is about 
but I having difficulties converting an imperative algorithm [1] into Haskell 
and think it would be easier if I was able to write it in a monadic style with 
operations to read and write from and to the streams.

I first tried to approach it by delving into the innards of other Stream 
functions to devise what I needed. I only got so far and the sticking point was 
defining the Monad. I then approached it from the Monad side and although what 
I have is workable, it probably isn't going to perform (for one it uses 
fromStream and tailS on each read off the front of the stream).

Data.Array.Parallel.Stream serves only one purpose: to represent loops produced by 
DPH in such a way that the compiler is able to optimise them well. Putting a monad 
on top of that will very very likely break this. To be honest, I'm not sure why 
you need the monad anyway. I would expect compression/decompression to be pure 
functions of type Stream Word8 -> Stream Word8.

In any case, I would urgently recommend not to use Data.Array.Parallel.Stream 
for anything at this point. This whole subsystem will soon die of old age and 
be replaced by the much nicer stuff from package vector, specifically 
Data.Vector.Fusion.Stream and Data.Vector.Fusion.Stream.Monadic. Note that the 
latter implements monadic streams as described in 
http://www.cse.unsw.edu.au/~rl/publications/recycling.html. Perhaps those can 
be useful for you if you really need a monad.

Roman
Thanks. No, I don't need a Monad and I suspected it was a bad idea. It was really needed for convenience as all I had to go on was a C implementaiton of arithmetic coding (which included a getc part-way through the code block which I hoped to map to something like a get from the stream). However thanks to Stephen I have something better to work from. I will also take a look at Data.Vector.Fusion.Stream.

Cheers

Mark

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to