I am trying to read data as doubled from stdin, manipulate them and write them as well. So far I have come to the following:
import qualified Data.ByteString.Lazy as B import Data.Binary.IEEE754 import Data.Binary.Get -- gives a list of doubles read from stdin listOfFloat64le = do empty <- isEmpty if empty then return [] else do v <- getFloat64le rest <- listOfFloat64le return (v : rest) -- delay signal by one delay us = 0 : us -- feedback system, add delayed version of signal to signal sys us = zipWith (+) us (delay us) main = do input <- B.getContents let hs = sys $ runGet listOfFloat64le input print $ take 10 hs
The idea is to bind data to a program, which is then transmitted through a feedback system before it is written to standard output. Although now it just prints the first 10 values.
It works, but does not seem lazy. Ie he has to read all the memory input. So:
dd if=/dev/urandom bs=8 count=10 | runhaskell feedback.hs
will work fine, but:
dd if=/dev/urandom | runhaskell feedback.hs
will not be. I assume this is a listOfFloat64le function that makes things work incorrectly. So, how do I create iterability to go into my sys function without having to read everything in memory?
I am not a very experienced haskeller.
source share