foldl1 (.) . fmap (f :: Int -> a -> a) [m..n] semantics in accellerate language?

Skip to first unread message


Sep 19, 2017, 5:11:15 PM9/19/17
to Accelerate
Asuming having a function

f :: Int -> a -> a

which should be used as kind of a generator function creating an a chained n times with an increasing Int which could be expressed in  std Haskell as

foo :: Int -> Int -> a -> a
foo i0 n
= foldl1 (.) . fmap f . take n  $ [i0..]

which takes an start index (i0) and the number of iterations (n) and gives you the function f applyed an increasing number from i0 to i0 + n and chaining the resulting functions to a single a -> a using a fold.


let a = foo 1 2 a0

should be the same as

let b = f 3 . f 2 . f 1 $ a0

The problem is that this does not work with the accellerate language as it does not allow Arrays of functions.
So using fmap to partialy apply the increasing i to the f function to then take the list of functions an combine them to a single (a -> a) using the fold does not work.

Havent found a way yet to express this in acccellerate other then the b above (writing the calls to f with increasing i and the chain them by hand.

Accellerate has a generate and a iterate function but i'd kind need a combination of those.
As mentioned above although a map function exists , but the mapped function is only allowed to return primitive values and not functions.

Any Ideas?

Trevor McDonell

Sep 22, 2017, 12:57:03 AM9/22/17
to Accelerate


Most likely, Accelerate will never support arrays of functions —- this goes against the design philosophy of data-parallelism, where we want to apply the same function to each element of an array.

Still, it may be possible to do what you want. Here is an example where I do something like what you propose above. It is not generating an array of functions, rather it just builds up a chain of operations to execute (which sounds more like what you want, actually).

Does that help?


You received this message because you are subscribed to the Google Groups "Accelerate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
Visit this group at
For more options, visit
Reply all
Reply to author
0 new messages