ghc and signal processing

MR K P SCHUPKE k.schupke at
Mon Feb 23 12:32:36 EST 2004

>b <- mapArray id a

The reason it is slow is because the array type is copied every time
a member is assigned.

There are two solutions:

1) Use a mutable-array in the StateMonad then freeze it.

2) In this particular case where processing is sequential (IE you
are only altering values based on *nearby* values, you can use streams.
One of the nicest features of Haskell is how lists (being lazy) operate
just like streams... 

So read the data into a list and define a filter of the type

filter :: [a] -> [a]

Your program then becomes:

main :: IO ()
main = do
	s <- getMyDataAsList()
	putMyList (filter s)

where the commands getMyDataAsList and putMyList have the types:

getMyDataAsList :: IO [a]

putMyList :: [a] -> IO ()

This should be fast, and also use very little memory.

	Keean Schupke.

More information about the Glasgow-haskell-users mailing list