Title: A Simple Semantics for Polymorphic Recursion*
1A 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.
2What is polymorphic recursion?
Compact list-like structure Okasaki98
size runs in O(log n), list length in O(n)
Polymorphic recursion useful in generic
programming Hinze00,HinzeJeuring02
3polymorphic recursion aka non-uniform
recursion
size Seq a?Int
size Seq (a,a)?Int
length a?Int
length a?Int
4Roadmap
- 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
Goal Haskell 98 Semantics
Simple Model for Polymorphic Recursion APLAS05
Demand in Haskell 98 JFP05
Simple Model for ML Polymorphism Ohori89
5Background Frame Models
is a frame model iff
6Simple 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
7Language for Polymorphic Recursion
- Language combines features of Kfoury93
Ohori89 - special pfix binder for polymorphic recursive
definitions - stratified type language simple, open, and
universal
Abstract Syntax for PR
8Type Syntax
Stratified Types
? is an instantiation
if, and only if
9Typing Rules for PR
PR rules Kfoury93
Hindley-Milner
Type system is syntax-oriented Kfoury93 I.e.,
derivations are unique modulo application
order of GEN rule.
10Typing Rules for PR
Leaf in the type derivation of size
11Pointed CPO Frames
- is a pcpo frame if each D?
is a pointed cpo w.r.t. , , and -
Ex.
For ? Int?Int,
Where continuity and fix are defined
conventionally
12Where do we solve equations such as
?
size Seq a?Int
size Seq (a,a)?Int
lives in DSeq(?)?Int
lives in DSeq(?? ?)?Int
13Defining 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
14Frame Semantics of PR
VAR
PFIX
where
Semantics defined by induction on type derivations
15Application Haskell Type Classes
The Eq class
defines () at infinitely many types
Without Poly-Rec, any Haskell program uses
finitely many, statically determinable instances
of () Jones94 not true with Poly-Rec
With the Simple Model, dictionaries are just
denotations
16Historical Note
Polymorphic Recursion entered Haskell through a
backdoor when certain expert programmers
noticed that the following variety of kludge
worked.
17Related Work
- Mycroft 84 introduced PR gave a model based on
ideals MacQueen, et al. 84 - Cousot 97 formulated a hierarchy of type systems
(including Mycrofts) 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
18Conclusions
- 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
Goal Haskell 98 Semantics
Simple Model for Polymorphic Recursion APLAS05
Demand in Haskell 98 JFP05
Simple Model for ML Polymorphism Ohori89