Encyclopedia

unfold/fold

unfold/fold

A program transformation where a recursive call to a function is unfolded to an instance of the function's body and then later an instance of the function's body is replaced by a call. E.g.

sumdouble l = sum (double l)

double l = case l of [] -> [] x:xs -> 2*x + double xs

==> (unfold double)

sumdouble l = sum (case l of [] -> [] x:xs -> 2*x : double xs)

==> (distribute over case)

sumdouble l = case l of [] -> sum [] x:xs -> sum (2*x : double xs)

==> (unfold sum)

sumdouble l = case l of [] -> 0 x:xs -> 2*x + sum (double xs)

==> (fold sumdouble)

sumdouble l = case l of [] -> 0 x:xs -> 2*x + sumdouble xs
This article is provided by FOLDOC - Free Online Dictionary of Computing (foldoc.org)
Mentioned in
Copyright © 2003-2025 Farlex, Inc Disclaimer
All content on this website, including dictionary, thesaurus, literature, geography, and other reference data is for informational purposes only. This information should not be considered complete, up to date, and is not intended to be used in place of a visit, consultation, or advice of a legal, medical, or any other professional.