{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
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
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/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
Image of page 2
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
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
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
Image of page 4
Type declaration in OCaml square4 First, type expressions are: square4 te = int | string | unit | … | te list | te * te * … * te 6/4/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
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 ]
Image of page 6
Image of page 7
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