Higher-Order Programming » Lab Sessions

Session 5 (Solutions)

Assistant: Steven Keuchel (steven.keuchel@vub.be)

Section 1: More higher-order functions on lists





Exercise 1:





Exercise 2:

  1. 
    
    
    
    
  2. 
    
    
    
    

Section 2: Streams

Exercise 3: Streams Primer





Exercise 4: Stream transformers

  1. Pairwise combination




  1. Prefix calculation

    
    
    
    
    
  2. Stream interleaving

    
    
    
    
    

Exercise 5: Numerical Approximation









Exercise 6: Collatz Streams

Finite (?) Collatz:





Infinite Collatz:





Numbers keep being printed on the stream, but as the stream is only generated while print-stream is recursively reading the next element of a stream, no out of memory error will be generated. However, the Read-Eval-Print Loop will be stuck. You can so stop the execution of the program using CTRL + K (⌘ + K on Mac).

Exercise 7: Streams Advanced