Section FoldLeft.
Variables (T R : Type) (f : R -> T -> R).
Fixpoint foldl z s := if s is x :: s' then foldl (f z x) s' else z.
End Flatten.
Prenex Implicits flatten shape reshape.
Arguments flattenP {A x}.

Lemma flatten_mapP (A : S -> seq T) s y :
reflect (exists2 x, x \in s & y \in A x) (y \in flatten (map A s)).