foldr/build question
Marcin 'Qrczak' Kowalczyk
qrczak@knm.org.pl
9 Apr 2001 16:27:06 GMT
I am currently improving immutable array functions, especially
listArray, elems, assocs, (==) and compare. (I am already as fast
as PackedString with a sequence type constructed from the improved
'UArray Int a' instantiated to a = Char, while its performance
is horrible with ghc-5.00's UArray.) I'm not sure how to enable
foldr/build fusion in all interesting cases.
The 'array' function uses foldr, OK. The 'elems' function could use
build, OK (it currently uses a list comprehension, but I will change
that). But what about listArray?
It consumes a list, but maintains a state through it: the next index
to fill. Am I right that there is no appropriate mechanism which would
let it virtualize a list coming from a good producer? The situation
is similar to take and drop.
Using STRef would be too silly, if possible at all :-)
The current implementation of listArray uses zip, and thus virtualizes
either the element list or the index list, but not both.
What I am really eliminating is the index->Int conversion with range
check on each element. But of course I should keep at least as much
as foldr/build fusion as currently, or more if possible.
--
__("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTĘPCZA
QRCZAK