lec2-2x2

lec2-2x2 - News CSE 130 Fall 2011 On webpage Suggested HW#1...

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

CSE 130: Fall 2011 Programming Languages Ranjit Jhala UC San Diego Lecture 2: A Crash Course in ML 1 News On webpage: • Suggested HW #1 • PA #1 (due next Fri 9/8) Please post questions to WebCT/TED Today: A crash course in ML contd… 2 Recap: ML’s holy trinity • Everything is an expression • Everything has a value • Everything has a type Expression Value Type 3 Complex types: Lists []; [] ’a list • Unbounded size • Can have lists of anything (e.g. lists of lists) • But… [1;2;3]; [1;2;3] int list [“a”;“b”; “c”^“d”]; [“a”;“b”; “cd”] string list [1+1;2+2;3+3;4+4]; [2;4;6;8] int list [(1,“a”^“b”);(3+4,“c”)]; [(1,“ab”);(7,“c”)] (int*string) list [[1];[2;3];[4;5;6]]; (int list) list [[1];[2;3];[4;5;6]]; 4

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

View Full Document
Complex types: Lists All elements must have same type [1; “pq”]; 5 Complex types: Lists List operator “Cons” [1] int list 1::[2;3]; [1;2;3] int list 1::[“b”; “cd”]; “a”::[“b”;“c”]; [“a”;“b”;“c”] string list 1::[]; :: Can only “cons” element to a list of same type 6 Complex types: Lists List operator “Append” int list [“a”]@[“b”]; [“a”;“b”] string list 1 @ [2;3]; []@[1]; [1] int list [1;2]@[3;4;5]; @ Can only append two lists [1;2;3;4;5] [1] @ [“a”;“b”]; … of the same type 7 Complex types: Lists List operator “head” int hd ([“a”]@[“b”]); “a” string hd []; hd [1;2]; hd Only take the head a nonempty list 1 8
Complex types: Lists List operator “tail” int list tl ([“a”]@[“b”]); [“b”] string list tl []; tl [1;2;3]; tl Only take the tail of nonempty list

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 7

lec2-2x2 - News CSE 130 Fall 2011 On webpage Suggested HW#1...

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

View Full Document
Ask a homework question - tutors are online