lec5 Datatypes and Recursion

lec5 Datatypes and Recursion - CSE 130 : Winter 2006 Quiz...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSE 130 : Winter 2006 Programming Languages Ranjit Jhala UC San Diego Lecture: Datatypes and Recursion Quiz What about more complex data ? • We’ve seen some base types and values: – Integers, Floats, Bool, String etc. • Some ways to build up types: – Products (tuples), records, “lists” – Functions • Design Principle: Orthogonality – Don’t clutter core language with stuff – Few, powerful orthogonal building techniques – Put “ derived ” types, values, functions in libraries Next: Building datatypes Three key ways to build complex types/values 1. “Each-of” types Value of T contains value of T1 and a value of T2 2. “One-of” types Value of T contains value of T1 or a value of T2 3. “Recursive” Value of T contains (sub)-value of same type T Suppose I wanted … … a program that processed lists of attributes • Name (string) • Age (integer) • DOB (int-int-int) • Address (string) • Height (float) • Alive (boolean) • Phone (int-int) • email (string) Many kinds of attributes: • too many to put in a record • can have multiple names, addresses, phones, emails etc. Want to store them in a list . Can I ? Constructing Datatypes t is a new datatype. A value of type t is either: a value of type t1 placed in a box labeled C1 Or a value of type t2 placed in a box labeled C2 Or Or a value of type tn placed in a box labeled Cn type t = C1 of t1 | C2 of t2 | | Cn of tn
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Suppose I wanted … Attributes: • Name (string) • Age (integer) • DOB (int-int-int) • Address (string) • Height (real) • Alive (boolean) • Phone (int-int) • email (string) type attrib = Name of string | Age of int | DOB of int*int*int | Address of string | Height of float | Alive of bool | Phone of int*int | Email of string ;; Creating Values How to create values of type
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

lec5 Datatypes and Recursion - CSE 130 : Winter 2006 Quiz...

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

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