CSE-321 Programming Languages Let-polymorphism 박성우 POSTECH May 22, 2006 System F 2 Typing Rules 3 Identity Function 4 Outline • • • • System F V Predicative polymorphic -calculus Let-polymorphism Value restriction 5 Predicative Polymorphic -Calculus • Sublanguage of System F – decidable type reconstruction System F let-polymorphism P.P. -calculus undecidable decidable 6 Types in P.P. -Calculus 7 Predicative Polymorphic -Calculus A variable is assigned a monotype. A type application uses a monotype. 8 Typing Rules 9 Polymorphic types in predicative polymorphic -calculus are USELESS! • • Let's apply id to two different types bool and int. 11 Outline • • • • System F V Predicative polymorphic -calculus V Let-polymorphism Value restriction 12 Let-binding • let x = e in e' – binds x to a polymorphic expression e. – allows multiple occurrences of x in e'. 13 Let-polymorphism 14 Reduction of let-bindings 15 Why not? 16 다음 셋 영화의 공통점은? 18 19 20 21 22 공통점? 23 Outline System F V Predicative polymorphic -calculus V Let-polymorphism V Implicit polymorphism – SML does not use let-polymorphism! • Value restriction • • • • 24 Implicit Polymorphism • No type abstraction, no type application • No type annotation in -abstraction • An expression may have multiple types: – x. x • bool ! bool, int ! int, ..., 8. ! 25 Type System 26 Example 27 Outline • • • • • System F V Predicative polymorphic -calculus V Let-polymorphism V Implicit polymorphism V Value restriction 28 Prototypical Example 29 Value Restriction • Expression in the rule Gen must be a syntactic value. • If not, it must be used monomorphically. 30 SML Example - let val id = (fn y => y) (fn z => z) in id true end; val it = true : bool - let val id = (fn y => y) (fn z => z) in (id true, id 1) end; stdIn:2.40-2.56 Error: operator and operand don't agree [literal] operator domain: bool operand: int in expression: id 1 - let val id = (fn y => y) (fn z => z) in id end; stdIn:1.1-1.46 Warning: type vars not generalized because of value restriction are instantiated to dummy types (X1,X2,...) val it = fn : ?.X1 -> ?.X1 31
© Copyright 2024 Paperzz