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 doesn’t 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
 Fall '10
 CS
 ObjectOriented Programming, Functional Programming, Polymorphism, Type theory, Polymorphism in objectoriented programming, Type inference

Click to edit the document details