02-More-OCaml - CS 421 Lecture 2: More OCaml s...

Info iconThis preview shows pages 1–8. 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

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight 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 Lecture 2: More OCaml s Announcements s Lecture outline s Types s let expressions s Scoping rules s Tuples and pattern-matching s Lists and pattern-matching 6/2/2009 1 6/2/2009 2 Announcements s Reminder: MP1 due 1:00PM CDT Wednesday s EWS machines to use: remlnx, gllnx1-40 (.ews.uiuc.edu) s No live lectures next Monday & Tuesday (June 8, 9) s Pre-recorded lecture videos will be posted on the web site s Limited course staff availability this weekend s Friday Sunday you are on your own! More OCaml s Functional language rely on e x p r e s s i o n e v a l u a t i o n rather than s t a t e m e n t e x e c u t i o n s Heavy use of recursion s Type inference s Dynamic memory allocation s Higher-order functions (will be covered in the second half of the course) 6/2/2009 3 Types s Basic: int, string, s Function: 1 2 n s e.g. int int int s Later in this class: tuples, lists 6/2/2009 4 Let expressions s At top level, use let to define variables and functions s Use let rec for recursive definitions, e . g . : let rec sumsqrs m = if m=0 then 0 else m*m + sumsqrs (m-1);; 6/2/2009 5 Nested let definitions let f x y = let z = sqrt(x+y) in x*z;; let f x y = let f a = a ^ \n in f (x^y) let sumsqrs n = let rec aux m = if m>n then 0 else m*m + aux (m+1) in aux 1;; 6/2/2009 6 Further Examples let z = and t = in z t let f x = let f y = in let f z = in f f 6/2/2009 7 Scope...
View Full Document

Page1 / 27

02-More-OCaml - CS 421 Lecture 2: More OCaml s...

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

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