scanl f q ls = q : case ls of [] -> [] x:xs -> scanl f (f q x) xs