@robeverest FromStream and ToStream forms and isomorphism between scalar-streams and vectors. Additionally, ToStream has been generalized to work on any shape because it is natural to do so. FromStream on the other hand, cannot be generalized as easy because of the possible mismatch between stream element extents, as you are well aware of. The only other sensible way to manage the conversion from streams to arrays, that I can think of, would be to generalize only the input argument and make the type signature:

  FromStream :: (Elt e, Shape sh) => acc aenv [Array sh e] -> PreOpenAcc acc aenv (Vector e)

which would imply flattening all the stream elements to vectors and appending them all into one big vector (but in an efficient way = permute). The reason we have to do it like this, is that the only way to combine all the extents in the stream into one extent of the resulting array, is to sum up the total sizes of the arrays. You could of course always reshape afterwards if you, for example, happen to know that all the extents in the stream are the same. I think this would actually be a better solution.

@mchakravarty There is no assumption that all arrays in a stream have got the same size. If there was, the following type signature would work:

  FromStream :: (Elt e, Shape sh) => acc aenv [Array sh e] -> PreOpenAcc acc aenv (Acc (sh:.Int) e)

which would be completely symmetrical to the signature for ToStream.