{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

02-More-OCaml - CS 421 Lecture 2 More OCaml Announcements...

Info icon This preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 421 Lecture 2: More OCaml square4 Announcements square4 Lecture outline square4 Types square4 let expressions square4 Scoping rules square4 Tuples and pattern-matching square4 Lists and pattern-matching 6/2/2009 1
Image of page 1

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

View Full Document Right Arrow Icon
6/2/2009 2 Announcements square4 Reminder: MP1 due 1:00PM CDT Wednesday square4 EWS machines to use: remlnx, gllnx1-40 (.ews.uiuc.edu) square4 No “live” lectures next Monday & Tuesday (June 8, 9) square4 Pre-recorded lecture videos will be posted on the web site square4 Limited course staff availability this weekend square4 Friday – Sunday you are on your own!
Image of page 2
More OCaml square4 Functional language – rely on expression evaluation rather than statement execution square4 Heavy use of recursion square4 Type inference square4 Dynamic memory allocation square4 “Higher-order functions” (will be covered in the second half of the course) 6/2/2009 3
Image of page 3

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

View Full Document Right Arrow Icon
Types square4 Basic: int, string, … square4 Function: τ 1 → τ 2 → τ n → τ square4 e.g. int int int square4 Later in this class: tuples, lists 6/2/2009 4
Image of page 4
Let expressions square4 At “top level,” use let to define variables and functions square4 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
Image of page 5

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

View Full Document Right Arrow Icon
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
Image of page 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
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern