[Haskell-cafe] Data.Foldable UArray

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sat Feb 22 20:17:17 UTC 2014


On Sat, Feb 22, 2014 at 07:15:22PM +0000, Dominic Steinitz wrote:
> > Since all 'Foldable' functions factor through 'toList', you can't go too
> > wrong by using '(foldableFunction . toList) myArray' wherever you would have
> > wanted to use 'foldableFunction myArray'.
> 
> Isn't this going to be rather inefficient? Presumably the point of
> using an array is to avoid using lists for an application where they
> are not appropriate?

(I'll take this opportunity to correct myself: I meant 'foldableFunction .
elems', not 'foldableFunction . toList')

Marcus's proposed Foldable instance used 'elems' anyway, and furthermore the
public API to UArray (which is just IArray) provides no other suitable means
of folding the elements, so there's hardly something "more efficient" to
compare to.

It would be interesting to see if a more efficient implementation of 'foldr'
and friends could be written using the internal interface, but I wouldn't be
terribly surprised if it were no better that the naive approach plus list
fusion.  (I'm far from expert though).

Tom


More information about the Haskell-Cafe mailing list