# V2 en vn e1e2en v1v2vn can be of any fixed size 9

• Notes
• ProfessorResolvePartridge10091
• 4

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

v2 … en vn (e1,e2,…,en) (v1,v2,…,vn) • Can be of any fixed size (9-3,“ab”^“cd”,7>8) (6, “abcd”, false) (int * string * bool) • Elements can have different types • Tuples can be nested in other tuples Complex types: Records {name=“sarah” ; age=31; pass=false} { name : string, age : int, pass : bool} Records are tuples with named elements… {name=“sarah”;age=31;pass=false}.age int 31 {age=31;name=“sarah”;pass=false}.age int 31 bool false {age=31;name=“sarah”;pass=false}.pass Complex types: Lists • Unbounded size • Can have lists of anything (e.g. lists of lists) [“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]]; Complex types: Lists [] : ’a list [] [] [] e1 v1 e2 v2 e3 v3 [ e1;e2;… ] [ v1;v2;… ] [ e1;e2;e3;… ] e1 : T e2 : T e3 : T [ e1;e2;e3;…] : T list All elements have the same type [1; “pq”] Complex types: list ..construct 1::[2;3] [1;2;3] int list 1::[“b”; “cd”]; Can only “cons” element to a list of same type Cons “operator” e1 v1 e2 v2 e1::e2 v1::v2 e1 : T e2 : T list e1::e2 : T list

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

4 Complex types: list …construct [1;2]@[3;4] [1;2;3;4] int list [email protected][“b”; “cd”]; Can only append lists of the same type Append “operator” e1 v1 e2 v2 [email protected] e1 : T list e2 : T list : T list [1]@[“b”; “cd”]; Complex types: list … deconstruct Reading the elements of a list: • Two “operators”: hd (head) and tl (tail) [1;2;3;4;5] [“a”;“b”; “cd”] [(1,“a”);(7,“c”)] [[];[1;2;3];[4;5]] hd [1;2;3;4;5] 1 int tl [1;2;3;4;5] [2;3;4;5] int list hd [“a”;“b”;“cd”] “a” string tl [“a”;“b”;“cd”] [“b”; “cd”] string list hd [(1,“a”);(7,“c”)] 1 int [(7; “c”] (int * string) list
This is the end of the preview. Sign up to access the rest of the document.
• Spring '10
• CS
• Sort, Expression, Type system

{[ 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