Overlapping windows on shared samples

A signal-processing prototype uses a pure lazy list with sharing. The function decode n returns n + 1 and takes exactly 3 ms per call. The notation [2,4..] denotes the unbounded sequence 2, 4, 6, and so on.


haskell
let samples = map decode [2,4..]
    early = sum (take 3 samples)
    later = sum (take 5 (drop 2 samples))
in early + later


map constructs elements lazily, take k selects k elements, and drop k skips k list cells without demanding their numeric contents. Both sums use the same samples binding. Assume the evaluator computes early before later, with no compiler transformations. Ignore all costs except calls to decode.


Find the final numeric result, the number of decode calls, and the total decoding time in ms. Enter each answer as a whole number.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Lazy Evaluation Questions: