This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: in zy ; ; 10 Example 3 let foo x = let (y,z) = x in zy ; ; 11 Example 4 let rec cat l = match l with >  h::t > h^(cat t) 12 Example 4 let rec cat l = match l with >  h::t > h^(cat t) ML doesnt know what the function does, or even that it terminates. ML only knows its type! 3 13 Example 5 let rec map f l = match l with >  h::t >(f h)::(map f t) 14 Example 5 let rec map f l = match l with >  h::t >(f h)::(map f t) 15 Inferring types with a Introduce unknown type vars Figure out equalities that must hold, and solve these equalities Remaining types vars get a forall and thus become the a, b, etc. 16 Example 6 let compose (f,g) x = f (g x) 17 Example 6 let compose (f,g) x = f (g x) 18 Example 7 let rec fold f cur l = match l with > cur  h::t > fold f (f h cur) t 4 19 Example 7 let rec fold f cur l = match l with > cur  h::t > fold f (f h cur) t...
View
Full
Document
This note was uploaded on 01/08/2011 for the course CSE cse130 taught by Professor Cs during the Fall '10 term at UCSD.
 Fall '10
 CS
 Polymorphism

Click to edit the document details