haskell - Get indices of Applicative Traversable without dummy -


let's have v, both applicative , traversable. how can v indices of v? concrete example, consider v3 linear. want v3 0 1 2.

one way use mapaccuml dummy, example:

snd $ t.mapaccuml      (\idx _ -> (idx + 1, idx))      0 (pure "") :: v3 int 

but (pure "") dummy feels inelegant. how can in more elegant way?

you not going escape using pure if doing applicative , traversable. it's function in classes gives value of type without having one.

also, dummy determines shape of value construct. consider type such lists, not values have same shape: how choose between constructing [0], [0,1] or [0,1,2]? (a pure-based dummy gives first one.)


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -