The purpose of this text is to guide a reader through the first step towards grokking continuations as presented in Haskell (callCC
not covered). The reader is assumed to have basic knowledge of Haskell including some understanding of monads.
Suppose we are given a list of lists of integers and we want to compute the sum of squares of products of those lists. This task naturally breaks down into three steps:
- Take product of each list of integers and thus form a new list of integers.
- In that list, square every integer, again forming a new list of integers.
- Summate the resulting list.
But to produce this algorithm we need to parse the whole problem and revert it (i. e. start with the last step): the problem's descriptions starts with "sum" and the corresponding algorithm starts with "product". Does it really need to be like this?