UNB/ CS/ David Bremner/ teaching/ cs3613/ tutorials/ CS3613 Tutorial 3

Types

Use pencil and paper to work out the type of the following function. Check your answer using DrRacket.

#lang plai-typed
(define (f a b c)
  (a (b c)))

Tail recursion

Complete the following tail recursive function to count the number of odd and even numbers in a list. You may use the built in functions odd? and even?. Use the racket debugger to test the stack usage of your function.

(define  (helper lst odds evens)
  (cond
    [(empty? lst) (list odds evens)]
        ;; missing two cases
    ))
(define (odds-evens lst)
    (helper lst 0 0))
    
(test (odds-evens (list 3 2 1 1 2 3 4 5 5 6)) (list 6 4))