haskell - Is there a zipWith function for arrays? -


i have 2 arrays of equal size , want combine them element-wise. best way this? array package doesn't seem provide zipwith equivalent function.

i'm reluctant make own function because main way can think of doing convert , forth lists. care speed , assume way not efficient way.

option 1: use repa. might performance benefit parallelism well, should care it.

option 2: indices using bounds. suggest avoiding list comprehensions in general; though other answer uses them correctly in case, may worthwhile in habit of doing right thing.

zipwitharr f xs ys = listarray (bounds xs) $ fmap (lifta2 f (xs !) (ys !)) (range (bounds xs)) 

the reason works haskell's lists lazy, , can treat them control structures (due various optimizations), though can not treat them containers. moreover, ghc evaluates expression @ once per lambda, in general not need worry done inefficiently.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -