I'm thinking specifically for signal processing. Let's say I wanted to do something like double the magnitude of an incoming signal. I would want it to be very fast, so I would want the signal to be held in contiguous memory (e.g. unboxed vectors). But this signal could go on indefinitely, so I would want it to be treated as an infinite list; I'd rather call map (*2) signal
once instead of calling it for every signal chunk.
Is there a data structure in Haskell that would buffer these data chunks so that I could get contiguous memory performance, but treat the data as an infinite stream?
This is just a long shot, but what about using streams of large enough chunks of unboxed vectors? This would have the advantage of vectors' performance, and at the same time, fusion thanks to streams.
Update: The idea is to define a newtype
such as:
import Data.Array.Unboxed
import Data.Stream
import Data.Word
newtype Word8Stream = Word8Stream (Stream (UArray Int Word8))
and then define the generic functions you need such as
smap :: (Word8 -> Word8) -> Word8Stream -> Word8Stream
smap f (Word8Stream s) = Word8Stream $ fmap (amap f) s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With