Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Simple Semantics for Polymorphic Recursion* William L. Harrison, Ph.D Department of Computer Science University of Missouri, Columbia * This research.

Similar presentations


Presentation on theme: "A Simple Semantics for Polymorphic Recursion* William L. Harrison, Ph.D Department of Computer Science University of Missouri, Columbia * This research."— Presentation transcript:

1 A Simple Semantics for Polymorphic Recursion* William L. Harrison, Ph.D Department of Computer Science University of Missouri, Columbia * This research supported in part by subcontract GPACS0016, System Information Assurance II, through OGI/Oregon Health & Sciences University.

2 What is polymorphic recursion? size runs in O(log n), list length in O(n) Compact list-like structure [Okasaki98] Polymorphic recursion useful in generic programming [Hinze00,HinzeJeuring02]

3 polymorphic recursion aka “non-uniform recursion” size :: Seq a  Int size :: Seq (a,a)  Int length :: [a]  Int

4 Roadmap Ohori 89 conservatively extends semantics of STLC to Core-ML Harrison/Kieburtz 05 extend to model & logic of Haskell demand Present work models recursion in Haskell Remaining aspects seem to fit well in this framework In particular, type classes Goal: H98 semantics akin to “Definition of Standard ML” Demand in Haskell 98 [JFP05] Simple Model for Polymorphic Recursion [APLAS05] Goal: Haskell 98 Semantics Simple Model for ML Polymorphism [Ohori89]

5 Background: Frame Models is a frame model iff

6 Simple Model for ML polymorphism; Ex: ( x.x) :  a.a  a Denotes at any instance Simple Model conservatively extends model of simply-typed -calculus An alternative [HarperMitchell93] is to model type quantifiers with type abstraction as in System F/polymorphic -calculus [Girard,Reynolds]

7 Language for Polymorphic Recursion Abstract Syntax for “PR” Language combines features of [Kfoury93] & [Ohori89] special “pfix” binder for polymorphic recursive definitions stratified type language: “simple”, “open”, and “universal”

8 Type Syntax  is an instantiation if, and only if Stratified Types

9 Typing Rules for PR  (x) = t  x : t , x :  M:   (fix x. M) :   (x) =     x : ( s  ) , x :  (pfix x. M) :  M: Hindley-Milner PR rules [Kfoury93] *Type system is syntax-oriented [Kfoury93]; I.e., derivations are unique modulo application order of GEN rule.

10 Typing Rules for PR  (x) =     x : ( s  ) , x :  (pfix x. M) :  M: Leaf in the type derivation of size …

11 is a pcpo frame if each D  is a pointed cpo w.r.t.,, and For  = [Int]  Int, … Where continuity and fix are defined conventionally: Ex. Pointed CPO Frames

12 size :: Seq a  Int size :: Seq (a,a)  Int “lives” in D Seq(  ’)  Int “lives” in D Seq(  ’   ’)  Int Where do we solve equations such as ?

13 Defining pcpo frame P in terms of a given pcpo frame D Frame Objects are type-indexed sets of values Other Structure (lub & p.o. defined pointwise) By Theorem 1 in the paper, P is a pcpo frame

14 Frame Semantics of PR VAR: PFIX: where Semantics defined by induction on type derivations

15 Application: Haskell Type Classes The “Eq” class Without Poly-Rec, any Haskell program uses finitely many, statically determinable instances of (==) [Jones94]; not true with Poly-Rec defines (==) at infinitely many types With the Simple Model, “dictionaries” are just denotations

16 Historical Note Polymorphic Recursion entered Haskell through a “backdoor” when certain expert programmers noticed that the following variety of kludge worked.

17 Related Work Mycroft 84 introduced PR; gave a model based on ideals [MacQueen, et al. 84] Cousot 97 formulated a hierarchy of type systems (including Mycroft’s) in terms of lattice of abstract interpretations of untyped lambda calculus Henglein 93 showed PR type inference is undecidable Kfoury, et al. 93, gave several type systems for PR; ours is called ML/1 ’ Models of Type classes [WadlerBlott89, Thatte94, StuckeySulzmann04] and Higher-order polymorphism [Jones93]

18 Conclusions “Textbook” semantics Substance of denotations change (type awareness) Form of semantic definitions mostly familiar Conservative extension of “Simple Model of ML Polymorphism” Straightforward, albeit non- trivial Present work models recursion in Haskell Remaining aspects seem to fit well: type classes & higher- order polymorphism Demand in Haskell 98 [JFP05] Simple Model for Polymorphic Recursion [APLAS05] Goal: Haskell 98 Semantics Simple Model for ML Polymorphism [Ohori89]


Download ppt "A Simple Semantics for Polymorphic Recursion* William L. Harrison, Ph.D Department of Computer Science University of Missouri, Columbia * This research."

Similar presentations


Ads by Google