lec7 Polymorphism

Lec7 Polymorphism - CSE 130 Fall 2006 Functions are"first-class values Arguments return values bindings What are the benefits Parameterized similar

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

View Full Document Right Arrow Icon
1 CSE 130 : Fall 2006 Programming Languages Ranjit Jhala UC San Diego Lecture 7: Polymorphism (or, whats the deal with ’a) Functions are “first-class” values • Arguments, return values, bindings … • What are the benefits ? Creating, (Returning) Functions Using, (Taking) Functions Parameterized, similar functions (e.g. Testers) Iterator, Accumul, Reuse computation pattern w/o exposing local info Compose Functions: Flexible way to build Complex functions from primitives. What is the deal with ’a ? These meta-functions have strange types: map: filter: Why ? (’a ’b) ’a list ’b list (’a bool) ’a list ’a list Polymorphism • Poly = many , morph = kind ’a * ’b ’b * ’a ’a and ’b are type variables! • For-all types: ’a,’b can be instantiated with any type: w/ int,string : int * string string * int w/ char , int list : char * int list int list * char w/ int int , bool : (int Int) * bool bool * (int int) let swap (x,y) = (y,x) For all ’a, ’b: ’a * ’b ’b * ’a Instantiation at Use map: let f x = x^“ like”;; let fm = map f [“cat”; “dog”; “burrito”];; (’a ’b) ’a list ’b list let f x
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/14/2008 for the course CSE 130 taught by Professor Jhala during the Fall '06 term at UCSD.

Page1 / 5

Lec7 Polymorphism - CSE 130 Fall 2006 Functions are"first-class values Arguments return values bindings What are the benefits Parameterized similar

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

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