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

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

View Full Document Right Arrow Icon
CS 421 Midterm review session s Outline s Overview s Your questions s General s Sample MT problems 6/30/2009 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
OCaml: currying let f x y = x + y let f (x,y) = x + y 6/30/2009 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
OCaml: list folding s Not on the midterm s Higher-order functions 6/30/2009 6
Background image of page 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
Background image of page 7

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

View Full DocumentRight Arrow Icon
s Only differences (that we care about): s * s + s ? s
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online