Midterm-Review

# Midterm-Review - CS 421 Midterm review session Outline...

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

CS 421 Midterm review session s Outline s Overview s Your questions s General s Sample MT problems 6/30/2009 1

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

View Full Document
Overview s Format s 75 minutes s Closed-book, closed-notes s No calculators, no phones, no computers, no talking s No clarifications s Content: s MPs s Lecture examples s Lecture slides s Mostly analysis + synthesis, not recall 6/30/2009 2
OCaml: tail recursion s No further computation follows the recursive call s TR example (MP2 p4): let rec concat_even l = match l with [] -> "" | s::[] -> "" s::s'::ss s' ^ concat_even ss ;; | s::s'::ss -> s' ^ concat_even ss ;; s Non-TR example (Fibonacci): let rec fib n = match n with 0 -> 1 | 1 -> 1 | _ -> fib (n-1) + fib (n-2) 6/30/2009 3

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

View Full Document
OCaml: nested let let f x y = let z = sqrt(x+y) in x*z;; let f x y = let z = … and t = … in … z … t … 6/30/2009 4
OCaml: currying let f x y = x + y let f (x,y) = x + y 6/30/2009 5

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

View Full Document
OCaml: list folding s Not on the midterm s Higher-order functions 6/30/2009 6
OCaml: function types s What is the datatype of (and how do we know): let f g = match g with (x::y)::z -> y | a::b -> b This function is wrong! f: ‘a list list -> (‘a list) or (‘a list list) let rec h a b = if a = [b] then true else h a (tl b) h: ‘a list list -> ‘a list -> bool 6/30/2009 7

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

View Full Document
s Only differences (that we care about): s * s + s ? s
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 22

Midterm-Review - CS 421 Midterm review session Outline...

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

View Full Document
Ask a homework question - tutors are online