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

Info iconThis 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 s Announcements s Lecture outline s Type declaration in OCaml s Trees s Polymorphic types s Abstract syntax 6/4/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
6/4/2009 2 Announcements s Reminder: no “live” lectures next Monday & Tuesday (June 8, 9) s Pre-recorded lecture videos have been posted on the web site s Reminder: limited course staff availability this weekend s Friday – Sunday you are on your own! s MP2 has been posted s Due 1:00PM Wednesday, June 10
Background image of page 2
Brief review s Tuples s Fixed-size, heterogeneous collections s Ex: (“hello”, “cs”, 421) s Type: string * string * int s Pairs s Tuples with two values s fst, snd functions s Lists s Variable-size, homogeneous collections s Ex: [1; 2; 3; 4; 5] s Type: int list s :: - cons, @ - append s [1; 2] @ (3 :: [4; 5]) = [1; 2; 3; 4; 5] 6/4/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
Brief review s Pattern matching s let incr_second_of_3 (x,y,z) = y+1;; s Type: `a * int * `c -> int s let sum_pair p = (fst p) + (snd p) s Type: int * int -> int s Match expressions s Pattern matching with choice among alternate options s let rec is_even lst = match lst with [] -> true | x::[] -> false | x::y::ys -> is_even ys s Type: `a list -> boolean 6/4/2009 4
Background image of page 4
Type declaration in OCaml s First, type expressions are: s te = int | string | unit | … | te list | te * te * … * te 6/4/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
s type t = te s After this, t is an abbreviation for te s Similar to “let” syntax for names s type t = C 1 [of te 1 ] | … | C n [of te n ] s Where C 1 , …, C n are constructor names – names that start with a capital letter s Values of type t are created by applying C 1 to value of type te 1 , or C 2 to value of type te 1 , etc. 6/4/2009
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/01/2009 for the course CS CS421 taught by Professor Kirillmechitov during the Summer '09 term at University of Illinois, Urbana Champaign.

Page1 / 20

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

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

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