sample_final - CS 421, Fall 2007 Sample Final Questions You...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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.

Page1 / 3

sample_final - CS 421, Fall 2007 Sample Final Questions You...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online