rewrite Stream with algebraic data type