{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

03-Even-More-OCaml

# 03-Even-More-OCaml - CS 421 Lecture 3 Even More OCaml...

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

CS 421 Lecture 3: Even More OCaml square4 Announcements square4 Lecture outline square4 Type declaration in OCaml square4 Trees square4 Polymorphic types square4 Abstract syntax 6/4/2009 1

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

View Full Document
6/4/2009 2 Announcements square4 Reminder: no “live” lectures next Monday & Tuesday (June 8, 9) square4 Pre-recorded lecture videos have been posted on the web site square4 Reminder: limited course staff availability this weekend square4 Friday – Sunday you are on your own! square4 MP2 has been posted square4 Due 1:00PM Wednesday, June 10
Brief review square4 Tuples square4 Fixed-size, heterogeneous collections square4 Ex: (“hello”, “cs”, 421) square4 Type: string * string * int square4 Pairs square4 Tuples with two values square4 fst, snd functions square4 Lists square4 Variable-size, homogeneous collections square4 Ex: [1; 2; 3; 4; 5] square4 Type: int list square4 :: - cons, @ - append square4 [1; 2] @ (3 :: [4; 5]) = [1; 2; 3; 4; 5] 6/4/2009 3

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

View Full Document
Brief review square4 Pattern matching square4 let incr_second_of_3 (x,y,z) = y+1;; square4 Type: `a * int * `c -> int square4 let sum_pair p = (fst p) + (snd p) square4 Type: int * int -> int square4 Match expressions square4 Pattern matching with choice among alternate options square4 let rec is_even lst = match lst with [] -> true | x::[] -> false | x::y::ys -> is_even ys square4 Type: `a list -> boolean 6/4/2009 4
Type declaration in OCaml square4 First, type expressions are: square4 te = int | string | unit | … | te list | te * te * … * te 6/4/2009 5

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

View Full Document
Type declaration in OCaml square4 type t = te square4 After this, t is an abbreviation for te square4 Similar to “let” syntax for names square4 type t = C 1 [of te 1 ] | … | C n [of te n ]
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