{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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 don’t 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)) in foldright (+) [2;3;4] 0 5.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern