This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS 421, Fall 2007 Sample Final Questions You should review the questions from the sample midterm exams, the real midterm exams, and the homework, as well as these question. 1. Write a function get primes : int -> int list that returns the list of primes less than or equal the input. You may use the built-in functions / and mod . You will probably want to write one or more auxiliary functions. Remember that 0 and 1 are not prime. 2. Write a tail-recursive function largest: int list -> int option that returns Some of the largest element in a list if there is one, or else None if the list is empty. 3. Write a function dividek n lst k , using Continuation Passing Style (CPS), that divides n successively by every number in the list, starting from the last element in the list. If a zero is encountered in the list, the function should pass 0 to k immediately, without doing any divisions . # dividek 6 [1;3;2] report;; Result: 1- : unit = () 4. a. Give the types for following functions (you dont have to derive them): let first lst = match lst with | a:: aa -> a;; let rest lst = match lst with | -> | a:: aa -> aa;; b. Use these types (i.e., start in an environment with these identifiers bound to these types) to give a type derivation for: let rec foldright f lst z = if lst = then z else (f (first lst) (foldright f (rest lst) z))...
View Full Document
This test prep was uploaded on 04/21/2008 for the course CS 421 taught by Professor Kamin during the Fall '08 term at University of Illinois at Urbana–Champaign.
- Fall '08