You are on page 1of 380

CALL-BY-PUSH-VALUE

Semantic Structures in Computation


Volume 2

Title of the Series:


Semantic Structures in Computation

Series Editor in Chief


Guo-Qiang Zhang
Case Western Reserve University
Department of Electrical Engineering and Computer Science
Olin 610, 10900 Euclid Avenue, Cleveland, OH 44106, USA
E-mail : gqz@eecs.cwru .edu

Scope of the Series


With the idea of partial information and approximation as the starting point, this
bookseries focuses on the interplay among computer science, logic, and mathematics
through algebraic, order-theoretic, topological, and categorical means , with the goal of
promoting cross-fertilization of ideas and advancing interdisciplinary research .

This bookseries provides a distinctive publication forum for collected works and
monographs on topics such as domain theory, programming semantics, types ,
concurrency, lambda calculi, topology and logic in computer science, and especially
applications in non-traditional and emerging areas in which the development of formal
semantics deepens our understanding of a computational phenomenon.

Editorial Board
Samson Abramsky, Oxford University, UK
Stephen Brookes, Carnegie Mellon University, Pittsburg, PA, USA
Edmund Clarke, Carnegie Mellon University, Pittsburg, PA, USA
Thierry Coquand, University of Goteborg, Sweden
Pierre-Louis Curien, PPS, CNRS-Universite Paris 7, France
Manfred Droste, TU Dresden, Germany
Abbas Edalat, Imperial College, London, UK
Achim Jung , University of Birmingham, UK
Klaus Keimel, TU Darmstadt, Germany
Ying-Ming Liu, Sichuan University, P.R. China
Michael Mislovc, Tulane University, New Orleans, LA, USA
Peter O'Hearn, Queen Mary & Westfield College, London, UK
William Rounds, University of Michigan , Ann Arbor, MI, USA
Jan Rutten , CWI, Amsterdam, The Netherlands
Glynn Winskel, University of Cambridge , UK
CALL-BY-PUSH-VALUE
A FunctionallImperative Synthesis

by

Paul Blain Levy


School of Computer Science,
University of Birmingham

SPRINGER SCIENCE+BUSINESS MEDIA, B.V.


A C.I.P. Catalogue record for this book is available from the Library of Congress.

ISBN 978-94-010-3752-5 ISBN 978-94-007-0954-6 (eBook)


DOI 10.1007/978-94-007-0954-6

Printed an acid-free paper

All Rights Reserved


© 2003 Springer Science+Business Media Dordrecht
Originally published by Kluwer Academic Publishers in 2003
Softcover reprint ofthe hardcover lst edition 2003
No part of this work may be reproduced, stored in a retrieval system, or transmitted
in any form or by any means, electronic, mechanical, photocopying, microfilming, recording
or otherwise, without written permission from the Publisher, with the exception
of any material supplied specifically for the purpose of being entered
and executed on a computer system, for exclusive use by the purchaser of the work.
Abstract
Call -b y-push- valu e (C BP V) is a new programming lan guage paradigm ,
based on t he sloga n "a value is, a computation does" , developing ear lier
work of Moggi and Filinski. We claim t hat CBPV pr ovid es t he semant ic
primit ives from which t he call-by-value and call-by-name paradigms ar e
built. T he primary goal of t he monograph is to pr esent t he evidence
for t his claim, which is found in a remarkably wide ran ge of semanti cs:
from op erational sem ant ics, in big-step form and in machine for m , t o
deno tational mod els using domains, po ssible worlds, cont inuations and
games.
In t he first part of t he monograph, we come to C BP V and it s equa-
tio nal theory by looking critically at the ca ll-by-value and call-by-name
paradigms in the presence of general com put ational effects. We give
a Felleisen /Friedman-style CK-machine semant ics, whic h exp lains how
CBPV can b e understood in t erms of push/pop instructions and leads
us to consider stack terms.
In the second part , we give simple CBPV models for pr inting, div er-
gence, global store, err ors, errat ic choice and control effects , as well as
for various combinat ions of these effects. We develop the store model
into a po ssib le world model for cell generat ion, and (following Steele)
we develop t he cont rol model into a "j um ping implementation" using a
cont inuat ion lan guage called Jump-Wi th-Argumen t (JWA) .
We pr esen t t he Abramsk y-Honda-M cCu sker pointer game model for
general st orage, in t he setting of both JWA and CBP V. We see infor-
mally how , b ecau se t hese languages make control flow explicit, we can
explain eac h of t he concepts of pointer games in concrete com put at ional
te r ms. In part icul ar , t he pointer ind icat e t he time of receip t of t he po int
being jumped to , and t he qu estion/answer dist incti on corres ponds to t he
two kinds of jump in C BP V: forcing and returning.
In t he t hird par t of t he monograph, we pr esent t he categoric al sem an-
t ics for CBPV extende d with st ack terms: it is an adj unct ion , resolving
t he st rong monad cons idered by Moggi. We see how each concrete
CBPV model we have treated is indeed an adjuncti on . Finally, we ex-
plain how each connective in both CBPV and JWA is modelled by a
representing object for an appropr iate fun ctor.
Contents

List of Fi gures XVll

Preface XXI

Acknowledgments xxv
Introduction XXVll

1.1 Computa t ional Effects XX Vlll

1.2 Recon ciling CBN and CBV XXIX

1.2.1 The Problem Of Two Paradigms xxix


1.2.2 A Single Language xxix
1.2.3 "Hasn 't T his Been Done By . . . ?" XXXI

1.3 The Case For Ca ll-By-P ush-Value XXXll

I.4 Conventions XXXll


1.4.1 Not ati on an d Terminology XXXll
1.4.2 Weakening XXXIll

1.5 A CBPV Primer xxxiii


1.5.1 Basic Features XXXllI

1.5.2 Example P rogram xxxiv


1.5.3 CBPV Makes Control Flow Explicit XXXVI

1.5.4 Valu e Types and Computation Types XXXVI

1.6 Structure of Thesis XXXVll

1.6.1 Goals XXXVll

1.6.2 Ch ap t er Ou tline XXXVllI

1.6.3 Cha pter Dep endence xl


1.6.4 Proofs xl

Vll
V lll CA LL-BY-PUSH- VALUE

Part I Language
1. CALL-BY-VALUE AND CALL-BY-NAME 3
1.1 Introduction 3
1.2 The Main Point Of T he Chapter 3
1.3 A Simp ly Typed A-Calculus 4
1.3.1 The Language 4
1.3.2 Product Types 4
1.3.3 Equations 6
1.3.4 Reversible Derivations 7
1.4 Adding Effects 8
1.5 The Principles Of Call-By-Va lue and Call-By-Name 8
1.6 Ca ll-By-Va lue 10
1.6.1 Operational Semantics 10
1.6.2 Denot at ional Semantics for print 11
1.6.3 Scott Semantics 13
1.6.4 The Monad Approach 14
1.6.5 Observational Equivalence 17
1.6.6 Coarse-Grain CBV vs. Fine-Grain CBV 17
1.7 Call-By- Name 18
1.7.1 Operational Semantics 18
1.7.2 Obse rvational Equivalence 18
1.7.3 CBN vs. Lazy 20
1.7.4 Denotational Semantics for print 21
1.7.5 Scott Semantics 22
1.7.6 Algebras and Plain Maps 23
1.8 Comparing CBV and CBN 25
2. CALL-BY-PUSH-VALUE : A SUBSUMING PARADIGM 27
2.1 Int roduct ion 27
2.1.1 Aims Of Chapter 27
2.1.2 CBV And CB N Lead To CBPV 28
2.2 Syntax 28
2.3 Operational Semantics Without Effects 30
2.3.1 Big-Step Semantics 30
2.3.2 CK-Machine 32
2.3.3 CK-Machine For Non-Closed Computations 33
2.3.4 Typing the CK-Machine 33
Contents IX

2.3.5 Op er ations On Stacks 36


2.3.6 Agreement Of Big-Step and CK-Machine Sem antics
37
2.4 Operational Semantics for print 37
2.4.1 Big-Step Semantics for print 37
2.4.2 CK-Machine For print 38
2.5 Observati on al Equivalence 39
2.6 Deno t ati on al Semanti cs 39
2.6.1 Valu es and Comput ations 39
2.6.2 Denotational Sem antics Of St acks 41
2.6.3 Monads and Algebras 41
2.7 Subsuming CBV and CBN 42
2.7.1 Fr om CBV to CBPV 42
2.7.2 Fr om CBN t o CBP V 43
2.8 CBP V As A Metalangu age 45
2.9 Useful Syn t acti c Sug ar 45
2.9.1 Pa ttern-Ma t ching 45
2.9.2 Commands 46
2.10 Computations Matter Most 47
3. COMPLEX VALUES AND EQUATIONAL THEORY 49
3.1 Introduction 49
3.2 Complex Values 50
3.3 Equations 51
3.4 CK-Machine Illuminat es ---+ Equati on s 52
3.5 Adding Complex Valu es is Comput ation-Unaffecting 54
3.6 The Problem With the CBPV Equational Theory 56
3.7 Complex St acks 57
3.8 Equational Theory For CBPV With St acks 58
3.9 Reversible Derivations 60
3.10 Example Isom orphisms Of Typ es 61
3.11 Triviali zati on 61
4. RECURSION AN D INFINITELY DEEP CBP V 65
4.1 Introducti on 65
4.2 Divergence and Recursion 66
4.2.1 Diver gent and Recursive Terms 66
x CALL-BY-PUSH- VAL UE

4.2.2 Type Recursion 68


4.3 Denotational Semantics Of Type Recursion 69
4.3.1 Bilimit-Compact Categories 69
4.3.2 Sub-Bilimit-Compact Categories 72
4.3.3 Minimal Invariants 73
4.3.4 Interpreting Recursive Types 75
4.4 Infinitely Deep Terms 77
4.4.1 Syntax 77
4.4.2 Partial Terms and Scott Semantics 78
4.5 Infinitely Deep Types 79
4.5.1 Syntax 79
4.5.2 Partial Types and Scott Semantics 79
4.6 The Inductivc/Coinductive Formulation ofInfinitely Deep
Syntax 80
4.7 Relationship Between Recursion and Infinitely Deep Syntax
82
4.8 Predomain Semantics For CBPV 83
4.8.1 Domains and Predomains 83
4.8.2 Interpreting Type Recursion In Predomains and
Domains 84

Part II Concrete Semantics


5. SIMPLE MODELS OF CBPV 89
5.1 Introduction 89
5.2 Semantics of Values 90
5.3 Global Store 91
5.3.1 The Language 91
5.3.2 Denotational Semantics 92
5.3.3 Combining Global Store With Other Effects 94
5.4 Control Effects 95
5.4.1 letstk and changestk 95
5.4.2 Typing Control Effects 96
5.4.3 Regarding nil As A Free Identifier 98
5.4.4 Observational Equivalenc e 100
5.4.5 Denotational Semantics 101
5.4.6 Combining Control Effects With Other Effects 105
5.5 Erratic Choice 107
Cont ents Xl

5.5.1 The Lan guage 107


5.5.2 Denot ational Semantics 107
5.5.3 Finit e Ch oice 109
5.5.4 New Model For May Testing 109
5.6 Errors 111
5.6.1 The Lan guage 111
5.6.2 Denotati onal Semantics 113
5.7 Summary 114
6. POSSIBLE WORLD MODEL FOR CELL GENERATION 117
6.1 Cell Generation 117
6.2 The Language 118
6.3 Operational Semantics 119
6.3.1 Worlds 119
6.3.2 Stores 120
6.3.3 Op erational Rules 121
6.3.4 Observatio nal Equivalence 122
6.4 Cell Typ es As Atom ic Typ es 122
6.5 Excluding Thunk Storage 123
6.6 Introducti on 124
6.6.1 What Is A Possible World Seman t ics? 124
6.6.2 Contributi on Of Cha pte r 125
6.6.3 St ores 125
6.6.4 P ossibl e Worlds Via CBPV Decompositi on 126
6.7 Denotational Seman ti cs 127
6.7.1 Semantics of Values 127
6.7.2 Semantics of Computations 128
6.7.3 A Computation Type Denotes A Contravariant
Functor 128
6.7.4
Semantics of Stacks 129
6.7.5
Summary 130
6.8 Combining Cell Generation With Other Effect s 131
6.8.1 Introducti on 131
6.8.2 Cell Generat ion + Printing 132
6.8.3 Cell Generation + Divergence 133
6.9 Related Models and P arametricity 135
6.10 Modelling Thunk Sto rage And Infini t ely Deep Typ es 137
Xll CALL-BY-PUSH- VALUE

7. JUMP-WITH-ARGUMENT 141
7.1 Introduction 141
7.2 The Language 142
7.3 Jumping 143
7.3.1 Intuitive Reading of Jump-With-Argument 143
7.3.2 Graphical Syntax For JWA 144
7.3.3 Execution 145
7.4 The StkPS Transform 148
7.4.1 StkPS Transform As Jumping Implementation 148
7.4.2 Related Transforms 149
7.5 C-Machine 151
7.5.1 C-Machine for Effect-Free JWA 151
7.5.2 Adapting the C-Machine for print 153
7.5.3 Relating Operational Semantics 154
7.5.4 Observational Equivalence 155
7.6 Equations 155
7.6.1 Equational Theory 155
7.6.2 Example Isomorphisms 156
7.7 JWA As A Type Theory For Classical Logic 157
7.8 The StkPS Transform Is An Equivalence 160
7.8.1 The Main Result 160
7.8.2 Complex Values 161
7.8.3 Equational Theory For CBPV+ Control 162
7.8.4 Representing CBPV+Stacks In CBPV+Control 163
7.8.5 Stacks and Complex Values Are Computation-Unaffecting
164
7.8.6 The StkPS Transform Between Equational Theories
166
8. POINTER GAMES 169
8.1 Introduction 169
8.1.1 Pointer Games And Their Problems 169
8.1.2 Contribution Of This Chapter 170
8.1.3 More Is Simpler 171
8.1.4 Cells As Objects 171
8.1.5 Related Work On Abstract Machines 173
8.1.6 Structure Of Chapter 174
8.2 Arenas In The Literature 174
Cont ents Xlll

8.2.1 Player / Opponent Labelling 174


8.2.2 Tokens Of An Arena 174
8.2.3 Arenas Versus Arena Families 175
8.2.4 Forests Versus Graphs 176
8.3 Pointer Game Semantics For Infinitary JWA + Storage 176
8.3.1 Typ es 176
8.3.2 Terms 180
8.3.3 1]- Expansion And Copy cat Behaviour 188
8.4 Semantics Of Terms 189
8.4.1 Categori cal Structure 190
8.4.2 Cell Generation 192
8.4.3 Claims 193
8.5 Pointer Game For Infinitary CBPV + Control + Storage 194
8.5.1 Pointer Game Via StkPS 194
8.5.2 Introducing Qu estions and Answers 195
8.5.3 Answer- Move Pointing To Answer-Move 197
8.6 Removing Control 198

Part III Categori cal Semantics


9. SEMANTICS IN ELEMENT STYLE 207
9.1 Countable vs. Finit e 207
9.2 Introducti on 207
9.3 Ca tegorical Preliminari es 208
9.3.1 Modules 208
9.3.2 Homset Functors 209
9.3.3 Some Notation 210
9.3.4 Locally Indexed Categor ies 210
9.3.5 OpGrothendieck Construction And Homset Functors
213
9.3.6 Locally Indexed Modules 215
9.3.7 Locally Indexed Natural Tran sformations 216
9.4 Modellin g Effect-Free Lan guages 216
9.4.1 Car tesian Categories and Sub sti tution Lemma 216
9.4.2 Products, Exponentials and Distributive Coproducts
217
9.5 Categorical Structures For Judgements Of JWA And CBPV
220
XI V CALL-BY-PUSH- VAL UE

9.5.1 In troducti on 220


9.5.2 Judgement Model of JWA 220
9.5.3 St acks In CBP V 221
9.5.4 Comp utations In CBP V 222
9.5.5 Enrichment 223
9.6 Connectives 225
9.6.1 Right Adjunctives- Inte rpreting U 225
9.6.2 Jumpwith s-Int erpreting -, 226
9.6.3 Left Adjunctives- Inte rpreting F 226
9.6.4 Products-Int erpreting IT 227
9.6.5 Exponentials-Int erpreting -7 229
9.6.6 Distributive Coproducts-Interpreting L 231
9.6.7 Tying It All Together 234
9.6.8 Adjuncti ons 235
9.7 Examples 236
9.7.1 Trivial Models Of CBP V 236
9.7.2 Eilenb erg-Moore Mode ls Of CBP V 236
9.7.3 Between J WA and CBP V 237
9.7.4 Erratic Ch oice 239
9.7.5 Global St ore 240
9.7.6 P ossible Worlds: P art 1 241
9.8 Families 243
9.8.1 Compos ite Connectives 243
9.8.2 Families Const ruction For JWA 246
9.8.3 Families Construction For CBPV 247
10. ALL MOD ELS ARE CATEGORICAL MODELS 249
10.1 Introduction 249
10.2 All Models Of x -Ca lculus Are Cartesian Categori es 249
10.2.1 The Theorem , Vaguely St ated 249
10.2.2 Fixing The Obj ect St ruc ture 250
10.2.3 What Is A Mod el Of x -Ca lculus? 251
10.2.4 The Theorem , Precisely St ated 253
10.3 All Mod els Of CBP V Are CBPV Adj unction Mode ls 254
10.4 All Models Of JWA Are JWA Module Models 259
10.5 Enrichment 260
11. REPRESENTING OBJEC T S 261
11.1 Introduction 261
Contents xv

11.2 Categorical Structures 262


11.2.1 Joint vs. Separate Naturality 262
11.2.2 Context Extension Functors 263
11.3 Representable Functors 264
11.3.1 Ordinary Category 264
11.3.2 Locally Indexed Category 266
11.3.3 Cartesian Category 267
11.3.4 Category With Right Modules 269
11.3.5 Cartesian Category With Left Modules 271
11.4 Parametrized Representability 273
11.5 Possible Worlds: Part 2 277
11.6 Adjunctions and Monads 278
11.6.1 Definitions of Adjunction 278
11.6.2 Terminality of Eilenberg-Moore 283
11.6.3 Kleisli and Co-Kleisli Adjunctions 284
11.6.4 CBV Is Kleisli, CBN Is Co-Kleisli 287

Part IV Conclusions
12. CONCLUSIONS, COMPARISONS AND FURTHER WORK 293
12.1 Summary of Achievements and Drawbacks 293
12.2 Simplifying Algebra Semantics 294
12.3 Advantages Of CBPV Over Monad And Linear Logic
Decompositions 294
12.4 Beyond Simple Types 296
12.4.1 Dependent Types 296
12.4.2 Polymorphism 297
12.5 Further Work 297
Appendices 298
Technical Treatment of CBV and CBN 299
A.l The Jumbo A-Calculus 300
A.1.1 Introduction 300
A.1.2 Tuple Types 300
A.1.3 Function Types 301
A.2 Languages and Translations 302
A.3 Call-By-Value 304
A.3.1 Coarse-Grain Call- By-Value 304
XVI CALL-BY-PUSH- VALUE

A.3.2 Fine-Grain Ca ll-By-Value 305


A.3.3 From CG-CBV To FG -CBV 308
A.4 Call -By-Name 311
A.5 The Lazy Paradigm 312
A.6 Subsuming FG-CBV and CBN 314
A.6.1 From FG-CBV to CBPV 314
A.6.2 From CBPV Back To FG-CBV 314
A.6.3 From CBN to CBPV 319
A.6.4 From CBPV Back To CBN 320
Mode ls In T he Sty le Of Power-Ro binson 327
B.l Int roducti on 328
B.2 Acti ons of Monoidal Categories 328
B.3 Frey d Categories 329
B.4 Judgement Model 330
B.5 Enr ichment 331
B,6 Connectives 331
B.7 Modelling CBPV 332
B.8 The Full Reflection 333
B.9 Theories 334
B,10 Conse rvativity 336

References 337

Index 345
List of Figures

1.1 Chapter and Section Dependence xli


1.1 Terms of >. boo I + 5
1.2 Big-Step Semantics for CBV with print 10
1.3 Big-Step Semantics for CBN with print 19
2.1 Terms of Basic Language 29
2.2 Big-Step Semantics for CBPV 31
2.3 CK-Machine For CBPV, With Types 34
2.4 CK-Machine For Non-Closed Computations 35
2.5 Typing Stacks 35
2.6 Translation of CBV types, values and returners 43
2.7 Translation of CBN types and terms 44
3.1 Varieties of CBPV 49
3.2 Complex Values 50
3.3 CBPV equat ions, using convent ions of Sect. 1.4.2 53
3.4 Definitions used in proof of Prop. 25 56
3.5 Complex Valu es and Stacks 57
3.6 Equational laws for CBPV + stacks, using op era-
tions of Sect. 2.3.5 59
3.7 Reversible derivations for CBPV with stacks 60
3.8 The x L:IT -+-Calculus 62
5.1 Typing Rules for Control Op erators 97
5.2 Varieties of CBPV with control 97
5.3 CK-Machine With Control 99
5.4 Typing Stacks in CBPV + Control 100

XVll
xv III CALL-BY-PUSH- VALUE

5.5 Translating CK-machine for CBPV into CK-machine


for CBPV+control 100
5.6 Semantics of types-two equivalent presentations 102
5.7 Continuations and Stacks 104
5.8 Big-Step Rules for Errors in CBPV 112
5.9 Summary of simp le CBPV models 115
5.10 Indu ced semantics for CBV and CBN function types 116
7.1 Terms of Jump-With-Argument, and its embed-
ding into CBPV+ Ans 144
7.2 Examples of Graphical Syntax for JWA 146
7.3 Example Program With Repeated Jumps-Please
Try This 149
7.4 T he StkPS transform from CBP V+control to JWA,
with prin ti ng 150
7.5 C-Machine for Jump-With-Argument 152
7.6 Complex Values For JWA 156
7.7 JWA equations , using conventions of Sect . 1.4.2 156
7.8 Reversible Derivations For JWA 157
7.9 The StkPS transform between various languages 160
7.10 Complex Values For CBPV-l-Control 162
7.11 Equational Theory For CBPV+Control 163
7.12 Representing f-k 164
7.13 Definitions used in proof of Prop. 83 165
7.14 StkPS Transform On Complex Values 166
7.15 Syntactic Isomorphisms a and f3 used in proof of
Prop. 80 167
8.1 Example P rogram and Context 181
8.2 Com mand That 1J-Expands to Fig. 8.1 188
10.1 Rules For A Signature 8 256
10.2 Dismantling and Concatenation (Incl uding Com-
plex Stacks And Operation Symbols) 256
10.3 Adjunction Model From A Direct Model (8,0) 259
A.1 Syntax and Equations of Jumbo A-calculus 302
A.2 Effectful Languages 303
A.3 Big-Step Semantics for CG-CBV-No Effects 305
A.4 Terms and Big-Step Semantics for FG-CBV 306
A.5 CBV equations, using conventions of Sect . 1.4.2 308
List of Figure s XIX

A.6 Translation from CG-CBV to FG-CBV 309


A.7 Big-Step Semantics for CBN-No Effects 311
A.8 CBN equations, using conventions of Sect. 1.4.2 312
A.9 Translation from lazy to FG-CBV: types, return-
ers, values 313
A.lO Translation of FG-CBV types, valu es and returners 315
1
A.11 The Reverse Translation _v - 317
A.12 Translation of CBN types and terms 319
1
A.13 The Reverse Translation _0- 323
Preface

This research monograph explores the surprising consequences of com-


bining, within a single programming language, imperative and functional
features . It was originally written as a PhD thesis [Levy, 2001] in the
Department of Computer Science, Queen Mary, University of London,
submitted (after corrections) in March 2001. Since then, much of the
theory-especially categorical semantics-has been simplified. As de-
tailed below , I have revised the text to incorporate these changes.
Although it is not a textbook, the monograph should be accessible to
a broad range of readers. At one extreme, a category theorist can read
Chap. 9 and Chap. 11 and omit all the discussions of syntax. At the
other extreme, a reader interested in operational ideas is recommended
the following trail.
1 Read the CBPV primer (Sect. 1.5), and understand the example pro-
gram informally.
2 Look at the CK-machine (Fig. 2.3) and run the example program on
it-as well as on the big-step semantics (Fig. 2.2) . Don't worry about
the arithmetic-just calculate sums when you please.
3 Learn the 3 operations on stacks (Sect. 2.3.5)
4 Read the description of Jump-With-Argument in Sect. 7.2-7.3, omit-
ting the motivating discussion, and follow the example execution.
Compare this with the C-machine (Fig. 7.5) . Try the exercise in
Fig. 7.3.
5 To grasp the StkPS transform from CBPV to JWA (Fig. 7.4), apply
it to the example CBPV program of Sect. 1.5.2, and execute the
resulting JWA program, both using the C-machine (compare this
to the CK-machine) and the jumping machine. See how the latter

XXI
XXII CALL-BY-PUSH- VAL UE

precisely describes t he informal underst anding in Sect. 1.5.2, where


both force and return instructions cause a jump.

6 F inally, noti ce t hat JWA is a fragment of CBP V (extended with a


free ty pe identifier Ans)- as shown in Fi g. 7.1, and t he C-machine
follows accordingly from t he CK-mac hine.

For readers between these two extremes, it is t he int erplay between op-
erationa l and denot ati onal aspects of CBPV that provides the greatest
int erest. This is most apparent in t he chapters on possible worlds and
pointer games.

Historical Background
• [Landin, 1966J explain ed how to combine fun ctional and imperative
features in a call-by-valu e setting, influ encing the Scheme and ML
progr amming lan guages.

• [Moggi, 1991J presented a denot ational fram ework for t his combina-
t ion using monad s.

• [Filinski, 1996J modified t his to incorporate call-by-na me, usin g a


"generalized let" const ruct, which evolved into t he sequencing con-
st ruct of CBPV.

Changes Since The PhD Thesis


In t he version submitted as a PhD t hesis, t he only terms consid-
ered were values and computations, and t here was a mismatch b etween
t he equational theory and catego rical semant ics using adj unctions. To
achieve a match, vari ous alternative but complicated categorical struc-
t ures were proposed in Par t III.
T he problem was solved in [Levy, 2003J, where it was shown that
introducing stack terms gives a perfect match with adj unction semantics.
T his development made Part III of the thesis obsolet e. So a mu ch shorter
and simpler Part III has now been substituted. (A short treatment of one
of t he alternative categorical struct ures survives as Appendix B.) St ack
te rms are introduced in Cha p. 2, and treated t hrougho ut t he book, along
wit h values and comp utations.
Another change is t he introduction of sub-bilimii-compact catego ries
(such as Cpo, and fun ctor categories to Cpo) in Sect . 4.3.2. Usin g t his
concept, t he semant ics of t hunk st orage in Sect . 6.10 has been greatly
simplified .
T he treatment of pointer games in Chap. 8 has bee n revised. The
previous version attempted to first explain t he CBP V mod el t o read ers
PREFA CE XXlll

who had not read about Jump-With-Argument , and only afte rwards
explain t he link. Bu t JWA is so fundamental to pointer games t hat t he
first acco unt of pointer games divorced from JWA was un convincing.
Consequ ently, JWA is now central to our account, and it is t he CBPV
mode l (wit h its qu esti on/answer distinction) t hat is treated afterwards.
JWA has also been integrated into Part III.

A newly discovered model for may-testing has been added at the last
minute-it appears in Sect. 5.5.4.

We have made som e cha nges in our notation to bring it into line with
common usage.

old new
pr oduce return (like in Java )
producer retur ner
outside stack
consumer continuation (like in ML )
cont inuation j um p-po int
O PS t ransform St kP S t ransfor m
os stk
let cos letstk
changecos changestk
enriched-compact bilim it-cornpact
exponent expo ne nt ial
value/ producer struct ure Freyd category
SE domain dom ain
SEAM pr edornain pr ed ornain
revised simply ty pe d A-ca lculus j umb o A-calculus
Revised-A jumbo A-calculus
isom orphism style naturality style
rep resent ation rep resen ting obj ect
(....u; ...) A{ . . . , i .Mi, . .. }
let x be V in M let V be x. M
print c; M print c. M (like in CCS )
M to x in M M to x. N
r I-h K: 11 rill. I- k Q
neverused ignored
SEAM Predom
SEstrict DomStr
SEAMpartmin Partmin

We use "ret urn" rather t ha n "produce", becau se it is com mon usage:


"t his program returns 3". We wri te pm, short for "pat tern-match", rather
t han case , because somet imes there is no case analysis, as there is only
one pattern.
XXIV CALL-BY-PUSH- VALUE

The definition of CBPV adjunction model has changed. In the PhD


thesis, there was no requirement for the function

D x x"\'. A-(Y'Z) -----+ ITiEIDx XA i(Y 'Z) forallX,Y,Z


LJt EI t
f 1----+ Ai.((X x ini)*1)
to be an isomorphism. Although the theorems about adjunction mod-
els were all correct, this omission was clearly a mistake. In the new
version, this requirement is used in Sect. 10.3 to prove the match be-
tween adjunction models and the CBPV equational theory with stack
terms. Incorporating this requirement in a non-ad hoc way has led to
a new presentation of products and exponentials as well as distributive
coproducts.
Finally, it is worth mentioning that two ways in which we develop
CBPV
• adding complex values and an equational theory (Chap. 3)
• allowing infinitely deep syntax (Chap. 4)
must, at the present time, be regarded as incompatible. For our justifi-
cation for adding complex values is that they can be removed from any
computation (Prop. 25) . The proof of this uses induction over terms, so
it relies on terms being finitely deep. It is hoped that future work will
remedy this.
Acknowledgments

I am most grateful to my PhD supervisor, Pet er O 'Hearn, for his con-


st an t ass istance and advice, and to numerous colleagues and friends at
Qu een Mar y, Boston University, Brandeis, Paris 7, Birmingham and else-
where. Discussions with Adam Eppendahl, Julian Gilb ey, Mart in Hy-
land, Ji m Laird, Olivier Laurent , Michael Ma rz , Gu y McC usker , Paul-
Andre Mellies, Eu geni o Moggi, J ohn Power , Uday Reddy, Paul Taylor
(whose macros are used for many of t he diagr ams here), Hayo Thielecke,
my examiners Ch ris Hankin and Gordon Plotkin, and many ot hers have
sh ap ed the material in all kinds of ways.
Finally, I am grateful to my par ents, Ru th and David Levy, for their
love and support.

xxv
Introduction

P B Levy, Call-By-Push-Value
© Kluwer Academic Publishers 2003
XXVlll CALL-BY-PUSH- VALUE

1.1 Computational Effects


Much attention has been devoted to functional languages with di-
vergence (nontermination), such as PCF [Plotkin, 1977], FPC [Plotkin,
1985], Haskell, Scheme and ML, and to their models. After all, it is
well-known that a language with full recursion must have divergent pro-
grams. Yet some of the most fundamental semantic issues involved in
these languages are far more general than is often realized, and (as we
will argue in Sect . 1.2) can be correctly understood only in the light of
this generality. They arise whenever we combine imperative and func-
tional features within a single language.
It may strike the reader as strange to regard divergence as an imper-
ative feature, for what could be more "purely functional" than PCF?
But it is a remarkable fact that the same core theory (the subject of
Chap. 1) applies when we add to the simply typed A-calculus any of the
following [Moggi, 1991]:

• divergence

• reading and assigning to a storage cell

• input and output

• erratic choice

• generating a new name or cell

• halting with an error message

• control effects (we shall explain these in Chap. 5)

Thus, whether or not diverge really is a command, it certainly behaves


like one. We call all these features computational effects or just effects.
In our exposition, we shall use print commands as our leading example
of an effect, rather than the more familiar diverge , because doing so
makes important distinctions clearer (as we shall argue in Sect. 1.2).
The first issue that arises for effectful languages is that-by contrast
with the simply typed A-calculus-order of evaluation matters. Whether
a program converges or diverges, whether a program prints hello or
prints goodbye, will depend on the evaluation order that the language
uses.
A priori, there are many evaluation orders that could be considered.
But two of them have been found to be significant, in the sense that
IN TR ODUCTION XX IX

t hey possess a wide range of elegant semantics": call-by -name (CBN)


and call-by-value (CBV) .

1.2 Reconciling CBN and CBV


1.2.1 The Problem Of Two Paradigms
Resear chers have developed ma ny semantics for CBN and CBV. Bu t
each time a new form of semantics is int roduced , each time a technical
result is proved , each time an ana lysis of semantic issues is presented,
we have to perform the work twice: once for CBN, once for CBV .
Here are some examples of this sit uation .
• In many int ro du ctory textbooks on t he semant ics of program mi ng
languages (e.g. [Gunter, 1995]), we are first shown a CBN language
and its ope rationa l semant ics. We are given a denotational semant ics
usin g doma ins and t his is prove d adequate. Next, we are shown a
CBV language and its operational semantics. We are given a deno-
tationa l semantics and this too is proved adequate.
• In [Hyland and Ong, 2000; Nickau, 1996] a game semantics is pre-
sented for a CBN language, and various technical properties ar e
proved. Then , in [Abramsky and McC usker , 1998; Honda and Yoshida,
1997], a game semantics is presented for a CBV language, and similar
technical prop erties are proved.
• In [Streicher and Reus, 1998], a machine semantics and continuation
semantics are presente d an d t heir agreement proved: first for a CBV
language, t hen for a CB N language.
• In [a les, 1982], a functor ca tegory semantics for a CBN language
is presented . T hen , in [Moggi, 90; Stark, 1994] a functor category
semantics for a CBV language is presented.
T his duplication of work is tireso me. Furthermore , it makes t he lan-
guages involved seem inherentl y ar bitrary. We would prefer to study a
single, canonical language.

1.2.2 A Single Language


How can the situation described in Sect . 1.2.1 be remedied? A first
suggestion is as follows.

1 A t hird m ethod of evaluat ion , call-by-need, is usefu l for im plem ent a t ion pu rposes. But it
lacks a clean denotation al semantics-at least for effect s ot he r t ha n div ergen ce a nd errat ic
cho ice whose speci al properties are ex ploite d in [Hen nessy, 1980] to provid e a call-by-nee d
model. So we sha ll not con sider ca ll-by -n eed .
xxx CALL-BY-PUSH- VALUE

Suppose we have a language £ in which both CBN and CBV programs can
be written. Then we need only give semantics for £ , and this automatically
provides semantics for CBN and CBV.

There is a basic problem with this approach. As an extreme example,


consider that CBN and CBV languages can both be translated into n-
calculus [Sangiorgi, 1999] so zr-calculus is "a language in which both
CBN and CBV programs can be written". But this does not relieve
us of the responsibility to provide (say) Scott semantics for CBN and
CBV, because we do not have such a semantics for 7f-calculus. For this
reason, it is essential for ,c to have a Scott semantics, a game semantics,
a continuation semantics, an operational semantics, etc.
But even where ,c does have all these semantics, there can be a more
subtle problem. As an example, consider that CBN can be translated
into CBV [Ratcliff and Danvy, 1997], and so CBV itself is "a language
in which both CBN and CBV programs can be written". Now in this
case ,c certainly has a Scott semantics, a game semantics, a continuation
semantics etc., and so, as proposed, we obtain semantics for CBN. But
the Scott semantics for CBN thus obtained is not the traditional CBN
Scott semantics. (For example, whereas in the traditional semantics
Xx.d i verge and diverge have the same denotation, in the new semantics
they have different denotations.) So the translation of CBN into CBV
does not relieve us of the task of constructing the traditional semantics
for CBN.
We see that, in order to remedy the situation described in Sect . 1.2.1,
we have to be sure that the Scott semantics for ,c induces the usual Scott
semantics for CBN and CBV, rather than a more complicated one; and
likewise for game semantics, continuation semantics, operational seman-
tics etc. Another way of saying this is that the translations from CBV
and from CBN into ,c must preserve Scott semantics, game semantics
etc.
Of course, it will be impossible to show that the translations preserve
every semantics we might wish to study. But the semantics we have
mentioned are extremely diverse, and if these are all preserved then this
makes a strong case that we do not need to continue investigating CBN
and CBV as independent entities.
We say then that the language ,c subsumes CBN and CBV, and that
the two translations into it are subsumptive. Notice that subsumptive-
ness is not a formal, technical property of a translation (such as full
abstraction). Rather, it says, informally, that there is no reason to re-
gard the source language as anything more than an arbitrary fragment
of the target language.
INTROD UCTION XXXI

1.2.3 "Hasn't This Been Done By ... ?"


There are many claims in t he lit erature that a given lan guage cont ains
both CBN and CBV:

• Moggi's mona dic metalanguage [Bent on and Wadl er , 1996; Moggi,


1991] and Filinski's variant [Filinski, 1996]
• CB V itself [Ra tcliff and Danvy, 1997]-in t he presence of general
effects, Moggi called t his t he computational A-calculus, or Ac calculus
[Moggi, 1988]
• zr-calculus [Sangiorgi, 1999]
• continuat ion languages [Plotkin, 1976], as well as t heir polarized
counterpart LLP [Laurent , 1999]
• languages bas ed on Girard 's linear logic [Benton and Wadler, 1996;
Girard, 1987]
• SF L [Marz et al., 1999] and SFPL [Marz, 2000].
Indeed t hese t ranslations , representati ons and encodings have provid ed
much insight and, in many cases, new models. Bu t we argue t hat t hey
do not achieve what we wan t.
We explained in Sect. 1.2.2 t hat CBV it self does not contain CBN in
our sense because t he equat ion Xx.di verge = diverge is invalidated by
t he t ranslation from CBN into CBV. The same critic ism applies to t he
translation from CB N to Moggi's metalan guage (alt hough not Filinski 's
variant) . Thus Moggi's lan guage does not subsume CBN in our sense ;
it is not a solut ion to our problem .
Filinski's variant does not have t his drawback, but both Moggi's
lan guage and Filinski 's vari ant have the drawb ack t hat t hey lack op-
erat iona l semant ics, essent ially becau se every term is a value. (Our
valu e/computation distinction in CBPV will remedy t his.)
We explained in Sect. 1.2.2 that zr-calculus does not have Scott seman-
ti cs (at least , not the kind we want) , so the translations int o it ar e not
subsumptive. Continuation calculi (and LLP) do have Scott sem antics,
bu t the CPS transforms into t hem do not preserve direct sem anti cs, so
t he CP S transforms (from source lan guages without cont rol effects) are
not subsumptive. The linear A-calculus of [Benton and Wadler , 1996]
does have Scot t semant ics, but , as rem arked there, t he lan guage is based
on t he assumption t hat effects are "commutat ive", so effects such as
printing are excluded .
The t ranslation from CBV to t he lan guage SF L does not preserve t he
1]-law for sum ty pes (exp lained in Sect . 1.8). By contrast , t he successor
XXXll CALL-BY-PUSH- VALUE

language SF P L does indeed subs ume CB V and CBN. It is in a sense


equivalent to t he computation part of CBPV, alt hough less sim ple.
In Chap. 12.3, we make further criticisms of Moggi's decom position
A -+ C B V B =A -+ TB
and of the linear decomposit ion
A -+CB N B =!A --<:J B

1.3 The Case For Call-By-Push-Value


In t his book we introduce a new lan guage parad igm, call-by-push-value
(CBPV). It is based on Filinski's variant of Moggi's "monadic metalan-
guage" [Filinski, 1996; Moggi, 1991], but we do not ass ume famili arity
wit h t hese calculi (discussed in Sect . 1.2.3 an d Sect. 12.3).
We shall see t hat CBPV satisfies all that was req uired in Sect . 1.2.2.
Consequently, what we previous ly regarded as t he primit ives of CBN and
CBV can now be seen as just idioms built from the genu ine pri miti ves
ofCBPV.
For t his reason, we argue that CBPV deserves the attention eve n 0]
those who are interested only in CBN (or on ly in CBV) and not in the
above problem of reconciling CBN and CBV. Such people benefit from
using CBPV because the CBN semantics they are studying will exhibit
t he decomposition of CBN primitives into CBPV primitives, so CBPV
is closer to the semantics. We will see numerous examples of this in
Part II.
We mention also that, although full abstraction is neither a necessary
nor a sufficient condit ion for subsumptiveness, we prove (Cor. 149 and
Cor. 159) t hat t he translations into CBPV are indeed fully abstract.
T hus, semanticists initially concerned with fully abstract mo dels for
CBV and CBN can obtain them from fully abstract models for CBPV.

1.4 Conventions
104.1 Notation and Terminology
We write V 'M for "M applied to V " . This operand-first notation
has some advantages over the traditional notation MV. In particu lar,
it allows the "push" reading of Sect. 1.5.1.
For any nat ur al number n , we write $n for {a, . . . , n - 1}, the canonical
set of size n .
In a category, we write ] ; 9 for the composit e of ] and 9 in diagram-
matic order.
We avoid the ambiguous word "variable", using instead the followin g
dist inct terms:
INTRODUCTION XXXlll

• An identifier is a syntactic symbol whose binding does not change,


as in A-calculus and predicate logic. A context is a list of distinct
identifiers, with associated types. A list giving the binding of each
identifier in a given context is called an environment.
• A cell is a memory location whose contents can change through time.
A list giving the contents of each cell in memory is called a store.
This crucial distinction between environment and store, attributed by
[Tennent and Ghica, 2000J to Park and his contemporaries [Park, 1968],
is maintained throughout our treatment.

1.4.2 Weakening
All the systems we treat have the weakening property: if I' f- M : B
then r, x : A f- M : B. We will often write the latter term not as M but
as x M. This explicit indication of weakening has two advantages.
• M and x M have different denotations: an environment for the latter
must provide a binding for x, even though this binding is not used.
• Writing x M implicitly includes the assumption that x rf. r, because
otherwise I' , x: A would not be a context.
As an example, the familiar 1]-law for functions is written
rf-M :A-+B
(1.1)
r f- M = AX.(X' XM) : A -+ B

We do not need to state explicitly that x rf. I', as is traditionally done.


In fact, to reduce clutter when writing equations, we will generally
omit the context, turnstile and type, and omit too all the assumptions
required to make the equations well typed. So, instead of writing (1.1),
we will just write
M = AX.(X' XM)

1.5 A CBPV Primer


1.5.1 Basic Features
The aim of this section is to enable the reader to understand a simple
example program. For this purpose, it suffices to explain the following
basic features.
• CBPV has a simple imperative reading in terms of a stack.
AX is understood as the command "pop x".
V' is understood as the command "push V".
XXXIV CALL-BY-PUSH- VALUE

• CBPV terms ar e classified into computations and values. A compu-


tat ion does som ething , whereas a value is somet hing like a b oolean
or nu mber which can be passed aro und.
Sl ogan A value is, a computation does .

• Only a value can be pushed or po pped. In ot her words , on ly a value


can be an operand. However , we can "freeze" a computation Minto
a value; this value is called the thunk of M [Ingerman, 1961] . Later ,
when desired, this thunk can be for ced (i.e. executed).
• Certain computations return values, or at least t hat is their goal; they
are called retu rn ers . If M is a returner, and N another computat ion,
then we can sequence them into the computation M t o x. N . This
means: first obey M un til fina lly it returns a value V, then obey N
wit h x boun d to V .

1.5.2 Example Program


The easiest way to grasp these basic ideas is to see an example pro-
gram explained very in form ally. The following program uses the com-
putational effect of printing messag es to the screen.
print "helloO".
let 3 be x .
let thunk (
print "hello!" .
AZ.
print "we just popped "z .
return x + Z
) be y.
print "hello2".
(print "he l l o3" .
7'
print "we just pushed 7".
force y
) to w.
print "w i s bound to "w.
return w + 5
We give a blow-by-blow account of execution-the program execute s
the commands in order. First it prints helloO , t hen binds x to 3, then
binds y to a thunk. If the word thunk were omitted, the program would
not typecheck, because an identifier can be bound only to a value-a
computation is too active to sit in an environment (list of bindings for
ident ifiers).
INTRODUCTION xxxv

Next, the program prints hello2 and the computation enclosed in


parentheses (from print "hello3" to force y), which as we shall see
is a returner, commences execution. This returner first prints hello3,
pushes 7, and prints we just pushed 7. Then it forces the thunk y.
So it prints hellol and pops z from the stack; i.e. it removes the top
entry (which is 7) from the stack and binds z to it. It reports we just
popped 7 and returns x + z which is 10.
So the returner enclosed in parentheses (from print "hello3" to
force y) has had the overall effect of printing several messages and
returning 10. Thus w becomes bound to 10 and the program prints w is
bound to 10. Finally the program returns w + 5 which is 15.
In summary the program outputs as follows

helloO
hello2
hello3
we just pushed 7
hellol
we just popped 7
w is bound to 10

and finally returns the value 15.


In more familiar terms, y is a procedure, 7 is the parameter that is
passed to it and it returns 10. But, compared to a typical high-level
language, CBPV is unusually liberal in that

• it allows the command print "we just pushed 7" to intervene be-
tween pushing the parameter 7 and calling the procedure;

• it allows the command print "hello 3" to intervene between the


start of the procedure and popping the parameter.
In a practical sense, this liberality is of little benefit, for the program
would have the same observable behaviour if the lines

7'
print "we just pushed 7".

were exchanged, and likewise if the lines

print "hello 3" .


AZ.
were exchanged. But it is this flexibility that allows CBPV to give a
fine-grain analysis of types.
XXXVI CALL-B Y-PUSH- VAL UE

1.5.3 CBPV Makes Control Flow Explicit


It is worth noticing t ha t t here ar e two lines in t his pro gram which
cause execution to move to another part of t he program, rather t han to
the next line. These are force y, where exec ut ion jumps to t he bod y
of t he t hunk t ha t y is bound to , and return x + z , where t he value
10 is returned to just after t he line force y. This illustrates a general
ph enomenon.
Onl y force and return ca use exec ution to move t o another par t of t he pro-
gram.
This kind of informati on about cont rol flow is mu ch less explicit in CBV
and CBN . For t his reason , as we shall see in Ch ap. 7 and Chap. 8,
it is beneficial to use CBPV when studying semant ics that des cribes
interaction between different parts of a program, such as continuation
semant ics or game semant ics.
Although force and return both ca use jumps, t here is an important
difference between t he two. A force instruction will specify where con-
t rol moves to: in the example pro gram, to y. By cont rast, a return
instruction will cause a jump to a point at the top of a stack, so it is
not specified explicit ly. This distinction is apparent in both cont inuat ion
semant ics and game semant ics.
In Cha p . 7, we look at a language ca lled Jump- Wit h-Argument where,
unlike CBP V, the destination of every jump is explicit . The t ranslation
from CBP V to JWA (called t he stack-passing-style t ransform) makes
explicit t he destinati on of a return instructi on.

1.5.4 Value Types and Computation Types


We said in Sect . 1.5.1 t hat CBPV has 2 disjoint classes of terms: values
and computations. It is t herefore unsurprising t ha t it has 2 disjoint
classes of types: value typ es and comp uta tion ty pes .
• A value has a valu e typ e.
• A computation has a computat ion type.
For example, nat and bool are valu e types.
The two classes of types ar e given by
value types A ::= UB [ L iE/A i I1IAx A
computation ty pes B ::= F A I D i E/ B i I A --+ B
where each set I of tags is finit e. (We will also be concerne d with
infinitely wide CBPV in which I may be countably infinite-see Sect. 4.1
for more discu ssion. ) We underline computation ty pes for clarity.
We explain t hese types as follows-notice how t his explanation main-
tains t he principl e "a value is, a computation does" .
INTRODUCTION XXXVII

• A value of type UB is a thunk of a computation of type B .

• A value of type LiE/Ai is a pair (i, V), where i E I and V is a value


of type Ai.

• A value of type 1 is an empty tuple O.


• A value of type A x A' is a pair (V, V'), where V is a value of type A
and V'is a value of type A'.

• A computation of type FA returns a value of type A.

• A computation of type TIiE1Bi pops a tag i E I from the stack, and


then behaves as a computation of type B i .

• A computation of type A -+ B pops a value of type A from the stack,


and then behaves as a computation of type B.

We have apparently excluded types such as boo L and nat from this,
but boo I can be recovered as 1 + 1. If we add type recursion as in
Sect. 4.2.2 , we can recover nat as J-lX.(l + X). In infinitely wide CBPV,
we can recover nat as LiENl.
Looking at the example computation of Sect . 1.5.2, we can see that its
type is Fnat because it returns a natural number. The identifier y has
type U(nat -+ Fnat). This means that the value to which y is bound is
a thunk (U) of a computation that pops a natural number (nat -+) and
then returns (F) a natural number (nat) .

1.6 Structure of Thesis


1.6.1 Goals
This book has two goals .

1 The main goal is to argue the claim made in Sect. I.3~to persuade the
reader that CBPV is significant by exhibiting a wide range of elegant
semantics, from which CBN and CBV semantics can be recovered.
This goal is the subject of Part II ; the preliminary work is done in
Chap . 2.

2 The second goal is to understand the categorical semantics of the


CBPV equational theory, introduced in Chap. 3. This goal is the
subject of Part III. We do not claim that this provides any further
motivation for CBPV.
XXXVlll CALL-BY-PUSH- VALUE

1.6.2 Chapter Outline


We begin by describing an intellectual journey t hat leads t o CBPV.
We do t his briefly- a full technical tre atme nt is given in t he Appendix.
T he journey starts in Chap . 1, where we exp lain t he language design
cho ices t hat characterize t he CBV and CB N paradigms, and we examine
t he consequences of t hese choices . We give both ope rationa l (big-st ep)
sema nt ics and denot ati on al semant ics in the presen ce of printing, our
leading example of a comput ational effect. (We look at divergence to o,
because of its familiarity.) We learn, most impor t antly, that CBV ty pes
and CBN types deno te different kinds of things- sets and A- sets (whi ch
we will define in Sect. 1.7.4) respe ct ively. By cons idering whi ch equat ions
are valid as observational equivalences, we see that function types b ehave
well in CBN but not in CBV, whereas sum types b eh ave well in CBV
but not in CBN .
This crit ical exp loration of CBV and CBN leads us, in Chap. 2, t o
CBP V. Because of the denot ati onal differen ce between CBV ty p es and
CBN type s, it is clear t hat t he subsuming language mu st have two
kinds of type. We give big-step and denotational semant ics (for printing
and for divergen ce) and we explain how CB V and CBN are subs umed
in CBP V. This comp letes t he journey. In addit ion, we give anot her
form of operational semant ics, t he CK -machine [Felleisen and Fri edman,
1986], wh ich makes precise t he push/pop reading t hat we illu strated in
Sect. 1.5.2. This machine gives us anot her clas s of terms-the stacks.
Wher eas fun cti on ty pes beh ave badly in CB V and sum ty pes beh ave
badly in CBN, in CBPV all ty pes beh ave well. We see this in Ch ap. 3
by giving an equational t heory for CBPV. We actually give 2 t heories:
withou t stacks and with stacks (t he lat t er conservat ively extends the
former). To pr esent t h is t heo ry, we have to extend CBP V with complex
values. However , as we expla in in Sect. 3.5, t his is not a problem , because
complex values can always b e removed from comp ut at ions and from
closed values.
Cha p. 4, the last chapter of P art I, look s at recursion and infinitary
CBP V. There is lit tl e original here (except t he noti on of "sub-bilimit -
compact ca tegory" ); it merely sets up materi al t hat is needed later in
Chap. 6, where we need to understand the sem antics of ty pe recursion
in order t o b e able to interpret t hunk storage, and in Chap. 8, where
we need infinitely deep sy ntax in order to obtain definability resul ts for
ty pes .
Having seen t he ope rational ideas and t he equational t heo ry we are
ready to give t he concrete semant ics of t he former (Part II ) and t he
categorical semantics of the lat ter (Part III).
INTRODUCTION XXXIX

In Chap. 5 we look at denotational semantics for a range of effects:


global store, control, errors, erratic choice, printing, divergence and var-
ious combinations of these. We learn that a useful heuristic for creating
CBPV semantics is to guess the form of the soundness theorem. Again
and again, throughout these examples, we see traditional semantics for
CBV primitives decomposing naturally into CBPV semantics. As for
the corresponding CBN models, some are new while others were known
but previously appeared mysterious-the CBPV decomposition makes
the structure of these semantics clear.
Both the store model and the control model from Chap. 5 are devel-
oped further in the subsequent chapters.
• The store model is developed in Chap. 6 into a possible world model
for cell generation, which captures some interesting intuitions about
CBPV: in particular, the idea that a thunk is something that can
be forced at any future time. This model is surprising in itself, as
previous possible world models (with the exception of [Ghica, 1997])
allow only the storage of ground values, whereas this model treats
storage of all values. But it also provides a good example of the
benefits of CBPV, because in the corresponding model for CBV [Levy,
2002] the semantics of functions is unwieldy-CBPV decomposes it
into manageable pieces.
• Based on the control model, we introduce in Chap. 7 another language
called Jump-With-Argument (JWA), equivalent to-but much sim-
pler than-CBPV with control effects. Unlike CBPV, Jump-With-
Argument is not really new, as it is essentially Steele's CPS interme-
diate language [Steele, 1978]. This language enables us to see that
the StkPS transform (the CBPV analogue of the CPS transform) pro-
vides a jumping implementation for CBPV, just as Steele explained
for CBV. We see how the explicit control flow described in Sect. 1.5.3
makes CBPV a good starting point for such an analysis.
Our final piece of evidence for the advantages of CBPV and JWA is
Hyland-Ong-style game semantics, which we discuss in Chap. 8. We
see once again that CBPV is much closer to the semantics than the
usual CBN languages (PCF and Idealized Algol) because of its explicit
control flow described in Sect. 1.5.3. Key notions of game semantics-
the question/answer distinction, pointers between moves, the bracketing
condition-become clearer from a CBPV and JWA viewpoint. For ex-
ample, we see that "asking a question" corresponds to forcing, while
"answering" corresponds to returning.
The goal of Part III is to present and analyze the structures required
to model
xl CA LL-BY-PUSH- VALUE

• effect-free language (simply ty ped A-calculus with sum, product and


expo nent ial typ es)

• CBP V with stacks

• JWA.
Of course t he effect-free lan guage is trea ted in t he literature, so our
treat me nt is essenti ally a recapi tulation, presented in such a way as to
smoo t h the transition to t he effectful languages.
Many of these categorical st ruct ures, such as products, can be given
an elementary definition using a univers al proper ty ( "element style") ,
and a mor e abstract definition using naturality. In Ch ap. 9 we present
all the required structures in an element style, and explain how we can
use this to interpret CBPV with st acks in a CBP V adjunction model , and
JWA in a JWA module m odel. We see how all the concrete denotational
sema nt ics from Parts I-II are instances of these structures.
Each of t he following 2 cha pters is a sequ el to Cha p . 9. Chap. 10 devel-
ops t he relationship between t he categorical structures and t he syntax,
showing t hat every model of t he equational t heory is a CBPV adj unction
model.
In Cha p. 11, we show t hat each connective of CBPV is a represen ting
object for a suitable fun ct or , which gives us a naturality style definition.
Furt hermore, we show t hat our so-ca lled "CBP V adj unction models" are
indeed adj unct ions in the usu al sense .
F ina lly, in Ch ap. 12, we look at some problems an d poss ible dir ecti ons
for fur ther work .

1.6.3 Chapter Dependence


The dependen ce between chapte rs and sections is shown in Fig. 1.1.
The target of each arrow dep ends on its source. T he diagram does not
cover examples, only the main text. Thus, we will sometimes describe
an example that dep ends on a chapter not indicated here.
The diagram indicates that Sect. 7.6-the JWA equational theory-
can be read without a ny preparation. That is true, if one refers to the
te rm synt ax in Fig. 7.1. However , this leaves out t he motivation for
JWA.

1.6.4 Proofs
We have usuall y omitted proofs which are st raightfo rward inductions,
and we have omitted pro ofs of resul ts for CBV and CBN where we have
given corresponding resu lt s for CBP V.
INTRO DUCTION xli

C hap . 3
e x ce pt 3 .5

4 .8

~
4 .4 -4 .5 6 .10
T
~"-"

/'~,
C hap . 8

7 .7
7 .8 /1
C h a p. 10
r a,

C hap . 11
.

Figure 1.1. Chapt er and Section Dep endence


I

LANGUAGE
Chapter 1

CALL-BY-VALUE AND CALL-BY-NAME

1.1 Introduction
T here is a certain tension in t he presentati on of CBPV: how mu ch
attent ion shall we devote to CBN and CBV? On t he one hand, we are
claiming t hat CBPV "subsumes" CBN and CB V, and to see how t hat is
achieved we have to discuss CB N and CBV, at least to some exte nt . On
the ot her hand, a t horough st udy of CBN and CBV would be a waste
of effort, since a primary pur pose of CB PV is to relieve us of t hat t ask.
Once we have CBPV (which we want to int roduce as early as poss ible) ,
CBV and CBN are seen to be just particular fragments of it .
The CBNj CBV material is t herefore organized as follows. In this
chapter, we look informally at t he key concepts and prop er ties of t hese
paradigms, assuming no prior knowledge of t hem. This provides back-
groun d for CBPV which we introduce in Cha p . 2. Bu t for t he interested
read er , we provide in Appe ndix A a t horough, technical t reatment of
CBN and CBV and t heir relationship to CBPV. T his chapter can t hus
be seen as a synopsis of App endix A.

1.2 The Main Point Of The Chapter


The main point of t he chap ter is t his:
CBV ty pes and CBN types denote different kinds of t hings.
This is true both for printing semant ics and for Scot t semantics:
• In our printing semant ics, a CB V type denotes a set whereas a CBN
typ e denotes an A -set (which we will define in Sect. 1.7.4) .

• In Scot t semant ics, a CBV ty pe denotes a cpo whereas a CBN typ e


denot es a pointed cpo.

3
P B Levy, Call-By-Push-Value
© Springer Science+Business Media Dordrecht 2003
4 CALL-B Y-P USH- VALUE

The importance of this main point is that it makes it clear why CBPV,
t he subsuming paradigm , will need to have two disjoint class es of typ e.
Unfortunately, the Scott semantics obscures this main point , because
a pointed cpo is a sp ecial kind of cp o. By cont rast, the class of sets
and the class of A-sets are (as will b e apparen t onc e we have defined
A-sets) disjoint. Thus printing illustrat es our main point much b etter
t han div ergen ce does . This is why we have chosen printing as our leading
example of a com put at ional effect .

1.3 A Simply Typed A-Calculus


1.3.1 The Language
Before we look at any computat ional effects, we study an effect- free
language. We look at the simply typed A-calculus whose only ground
type is a boolean type, extended with binary sum types ; we call this
A bool +. Its types are

A ..= bool I A + A I A -+ A
and its terms are given in Fi g. 1.1. We write pm for "pat tern-match" ;
and recall that we write ' for op erand-first application. While let is
not strictly necessary (let M be x. N ca n be desugared as M 'AXN) , it
is convenient to include it as a primitive.
A booI-l- has a straightforward semantics wh er e typ es denote sets and
t erms denote functions . A closed t erm of ty pe bool den otes either true
or false; there is an easy decision procedure to find whi ch. We ca ll bool
the ground type.

1.3.2 Product Types


Suppose we want to add product types A x A'to A booI-l-. It is clear
what the introduction rule should be:
r f- M :A r f- M ' : A'
r f- (M , M ') : A x A'

But we have a choice as to t he form of the eliminat ion rule. Either we


ca n use proj ections :
r f- M : A x A' r f- M : A x A'
rf-?rM:A r f- ?r'M : A'
Or we can use pattern-matching :
r f- M : A x A' r , x : A , y: A' f- N :B
r f- pm Mas (x,y) .N : B
Call-B y- Value and Call-By-Name 5

f l-- M: A f ,x :AI-- N : B
r , x: A , r ' I-- x : A r I-- let M be x. N : B

I' I-- true: bool I' I-- false: bool

f I-- M : bool f I-- N : B f I-- N ' : B


r I-- i f M then N else N' : B

f l-- M : A f l-- M : A'


r I-- inl M : A + A' f I-- inr M : A + A'
r I-- M : A + A' f , x : A I-- N : B f, x : A' I-- N ' : B
I' I-- pm M as {i nl x.N, inr x.N'} : B

f , x: A I-- M : B f l--M :A fl--N:A -+B


I' I-- Ax.M : A -+ B f l--M'N: B

Figure 1.1. Terms of A bool+

At first sight , t he cho ice b etween projections and pat tern-mat chi ng
seems unim portant , b ecause t hese two forms of elimination r ule are
equivalent:

7fM pm M a s (x, y). x


7f'M pm M a s (x, y). y
pm M as (x, y ).N let 7fM be x, 7f'M be y. N

In t he presence of effect s (C BN and CBV), however , these equat ions are


not necessari ly valid and the choice does mat t er. This is di scussed in
App en dix A.
Notic e

• t he resemblance b et ween a pattern-match product and a sum typ e-


each of t hese typ es has an elimination rule using pat t ern-mat ching

• t he resemblance b etween a projection pro duct and a fun ct ion typ e


from {O, 1}. For we can t hink ofa tuple (M , M' ) of proj ecti on product
type as a function taking 0 t o M and 1 t o M ' . To emphasize this
6 CALL-BY-PUSH- VALUE

resemblance, we use a novel notation: we write

(M,M') as A{O.M,l.M'}
7rM as O'M
7r'M as I'M

Because of these resemblances, we can understand the key issues in CBV


and CBN without having to include products. That is why, in this
chapter, we will not consider product types further. They are dealt with
fully in Appendix A.
There are more type constructors we could include while remaining
simply typed, and in Appendix A we will include them so that our
treatment of CBV and CBN there is as thorough as possible. The type
system used in this chapter, therefore, provides only a fragment of the
full type system that a (simply typed) CBN or CBV language can allow.
However, our aim here is just to explain the key ideas, and the types in
A boo I + are quite sufficient for that purpose.

1.3.3 Equations
Each type constructor (---+ , boo L, +) has two associated equations called
the fJ-law and the 1J-law.
We look first at the fJ-laws, which ar e straightforward.
• The fJ-law for A ---+ B :

M'AX.N = N[M/x]

• The fJ-Iaws for boo I :

i f true then N else N' = N


if false then N else N' = N'

• The fJ-laws for A + A' :


pm inl M as {inl x.N, inr x.N'} = N[M/x]
pm inr M as {inl x.N, inr x.N'} = N'[M Ix]

• There is also a fJ-law for let :

let M be x. N = N[M/x]
We next turn to the 1J-laws. They ar e more subtle than the fJ-laws,
but they are important in understanding the CBV/CBN issues. So we
Call-By- Value and Call-By -Nam e 7

look at them carefully and understand why t hey are valid in t he set
semantics.

• T he 17-law for A -+ B : any term M of ty pe A -+ B can be expanded

M = AX (X ' XM )

• The 17-law1 for boo I: if M has a free identifier z : boo I t hen for any
term N of typ e boo l

M[N/ z] = if N then M[tr ue/z] else M [f a l s e / z] (1.3)

Intuitively, t his holds becau se, in a given enviro nment (list of bindings
for identifiers) , N denotes eit her true or false .
• The 17-law for A + A' : if M has a free identifier z : A + A' t hen for
any term N of typ e A + A'

M[N/ z ] = pm N as {i nl x. XM[i n l x/ z]' inr x. XM' [i nr x/z]}

Notice t he similarity between sum ty pes and boo I .

1.3.4 Reversib le D erivat io ns


As a consequence of t hese equat ions, we have reversible derivation s,
e.g. for -+
r , A f- B
r f- A -+B
T his mean s that from a term of t he form r , x : A f- M : B (ass uming
x t/. r ) we can const ruct a term of t he form r f- N : A -+ B a nd vice
versa and that t hese operations are inverse up to provable equality. T he
reversible derivation is given by
• t he operation f) : M t---7 Ax.M , which turns a term I' , x : A f- M : B
int o a term r f- N : A -+ B
• t he conte xt f) - I: N t---7 x' N , which turns a te rm r f- N : A -+ B int o
a term I' , x : A f- M : B

1 Some a ut ho rs e.g. [Gira rd et al., 1988] give the name "7j-law" to t he wea ker eq uation
M = if M t hen true else f a l s e (Ll)
to gether with t he com mu ting conversi on law
M [if N then P e lse pi / z] = i f N then M [P/ z ] else M [pl / z] (1.2)
or a variant of t his . (1.1)- (1.2) tog et her a re equivalent to ou r 7j-law (1.3).
8 CALL-BY-PUSH- VALUE

and it is clear that these operations ar e invers e up to provable equality,


using t he f3- and TJ- laws for -t .
The reversible derivations for bool and + ar e
r l-B r l-B r , A I- B r , A' I- B
r ,bool l- B r ,A+ A' I- B
Readers fam iliar with categori cal semantics will see that these re-
versible derivations provide important information about the categorical
structure of an equat ional theory.

1.4 Adding Effects


We now wish to add a computa tional effect to A bool+ , and we
will use output as our example. We suppose that to any term we
can prefix a command such as print "hello ". For exa mple, the term
pr int "hello". t rue when evaluated, prints hello and then returns
t r ue .
We write A for the set of characters that can be print ed , A * for the
set of finite strings of characters, * for concate nat ion of strings and " "
for the empty string. Formally, we add to the term syntax the following
ru le, for every character c E A:
rl-M:B
I' I- print c. M : B

There are other, equivalent , syntactic possibilities, e.g. in CBV we could


let commands have type 1, as in ML. But we prefer commands to be
prefixes. This is for the sake of consistency between CE N, CBV, CBPV
and the Jump-With-Argument language discussed in Chap. 7.

1.5 The Principles Of Call-By-Value and


Call-By-Name
The first consequence of adding effects is that, by cont rast with pure
A bool+ , t he order of evalua tion matters. Given a closed term of type
bool , the output depends on the evaluation order. For some effect s the
answer too will dep end on t he evaluation order , but for output that is
not the case. The two evaluat ion orders we will look at ar e CBV and
CBN. We describe the princip les of these two paradigms.
Firstl y, in both CBV and CBN, we do not evalua te under A. Thus a A-
abst raction is term inal , in the sense that it requires no further evaluation.
Having decided not to evaluate under A, we have numerous choices
still to make .
Call-By- Value and Call-By-Name 9

1 To evaluate the term let M be x. N, do we


(a) evaluate M to T and then evaluate N[T/x]' or
(b) leave M alone, and just evaluate N[M/x]'?
2 To evaluate a term M of sum type, we must first evaluate it to inl N
or inr N . Do we then
(a) continue to evaluate N to T, so that M evaluates to inl T or
inr T, or
(b) stop there, declaring that inl Nand inr N are always terminal?
3 To evaluate an application such as M' N, we certainly need to evaluate
N, giving say AX.P. Besides this, do we
(a) evaluate M to T (either before or after evaluating N) and then
evaluate P[T Ix] , or
(b) leave M alone, and just evaluate P[M/x]'?
In fact, there is one fundamental question whose answer will deter-
mine how we answer questions (1)-(3): what may we substitute for an
identifier? At one extreme, we allow only a terminal term to replace
an identifier-this defines the CBV paradigm. At the other extreme,
we allow only a totally unevaluated term to replace an identifier-this
defines the CBN paradigm.
To each of questions (1)-(3), CBV requires us to answer (a) and CBN
requires us to answer (b). In the case of questions (1) and (3), this is
clear because substitution is involved. For question (2), it requires some
explanation. Consider a term such as
pm M as {inl x.N, inr y.N'}
To evaluate this we must first evaluate M. Suppose we evaluate M to
inl M'. In CBN we must not proceed to evaluate M', because we want
to substitute it for x in N, so it must be completely unevaluated. In CBV
we must evaluate M' to a terminal term T , so that we can substitute T
for x in N.
In conclusion, we emphasize the following point:
The essential difference between CBV and CBN is not (as is often thought)
the way that application is evaluated; rather it is what an identifier may be
bound to .
Notice that within the CBV paradigm, we have the choice of whether,
when evaluating an application M'N, we evaluate M before N or vice
versa. In fact, so long as we are consistent, the semantic theory is
essentially unaffected. Arbitrarily, we stipulate that we evaluate the
operand M before the operator N.
10 CALL-BY-PUSH- VALUE

1.6 Call-By-Value
1.6.1 Operational Semantics
In CBV a closed term wh ich is terminal is called a closed valu e. These
are given by
v "= true I false I inl V I i nr V I Ax .M
Every closed term M prints a string of cha racters m and then return s
a closed value V. We write M -IJ. m , V . T his is defined ind uctively in
Fig. 1.2.

M.ij.m ,V N[V/ x].ij.m' ,W

let M be x. N .ij. m * m', W

true .ij. "" , true false .ij. "" , false

M .ij. m , true N.ij. m' , V M.ij.m, f alse N'.ij.m' ,V

if M then N else N ' .ij. m * m' , V i f M then N else N ' .ij. m * m' , V

M.ij.m ,V M.ij.m ,V

inl M .ij. m , i nl V i nr M .ij. m , i nr V

M .ij. m , i nl V N[ V / x] .ij. m ' , W

pm M as {inl x.N , i nr x .N'}.ij. m * m' , W

M.ij.m ,inrV N' [V/ x].ij.m' ,W

pm M a s {inl x.N, inr x .N'}.ij. m * m' , W

M .ij. m , V N.ij. m' , Ax.N ' N ' [V/ x].ij.m" , W

Ax.M .ij."" , AX.M M 'N .ij.m*m' *m" ,W

M .ij. m,V

print c. M .ij. c * m , V

Figure 1.2. Big-St ep Semantics for CBV with print

Proposition 1 For every M there is a unique m , V such that M -IJ.


m ,V. D

The proof is similar to t ha t of Prop. 10.


Call-By- Value and Call-By-Name 11

1.6.2 Denotational Semantics for print


Definition 1.1 • The following CBV terms are called values :

V ::= x I true I false I inl V I inr V I Ax.M


(This generalizes t he not ion of "closed value" we have already used .)

• All CBV terms are called returners. (This is be cause their goal is to
return a value.)
D

Notice that a term is a value iff every closed substitution instance (sub-
st ituting only closed values) is a closed value.
We now des cribe and explain a denotational semantics for the CBV
printing language. The key principl e is that
each ty pe A denotes a set [A] whose elements are t he denot ations of closed
values of type A .
Thus the typ e boo l denotes the 2-element set {true, false} because ther e
are two closed values of type boo l . Likewise the typ e A + A' denotes
[A] + [A'] because a closed value of ty pe A + A' must be eit her of the
form inl V , where V is a closed value of type A , or of t he form inr V ,
where V is a closed value of typ e A'. We sh all come to A -+ B presently.
Given a closed value V of typ e A , we write [v] val for the element of
[A] that it denot es. Given a closed returner M of typ e A , we recall that
M prints a string of characte rs m E A* and then returns a closed value
V of typ e A. So M will denote an element [Ml et of A* x [A]. Thus a
closed value V will have two denotations [v]val and [Vl et related by

[Vr et = ("", [V]val)

A closed value of type A -+ B is of the form Ax.M. This, when applied


to a closed value of type A gives a closed returner of typ e B. So A -+ B
denotes [A] -+ (A* x [B]) . It is true that the syntax appears to allow us
to apply Ax.M to any returner N of type A , not just t o a value. But N
will be evaluated before it interacts with Ax.M, so Ax.M is really only
applied to the value that N returns.
Given a context r = Xo : A o, . . . , Xn -l : A n - l , an environment (list of
bindings for identifiers) associates to each Xi a closed value of ty pe Ai.
So the environment denotes an element of [A o] x ... x [A n - l ] , and we
wri te [r] for this set.
Given a value r f- V : B , we see that V , t ogether with an env ironment ,
gives (by substitution) a closed value of type B. So V denot es a funct ion
[v]val from [r] to [B].
12 CA LL-BY-PUSH- VALUE

Given a returner I' f- M : B , we see t hat M , together wit h an en-


vironment, gives (by substitution) a closed returner of type B . So M
denotes a function [Mret from [r] to A * x [B ].
Generalizing what we saw for closed value s, an arbitrary value V will
have two denotations [v]val and [Vr et related by
[v]retp = ("" , [V]valp)
for each environment p.
In summary, the denotational semantics is organized as follows.
• A type A denotes a set [A] .
• A context Xo : A o, . . . , Xn - l : A n- 1 denotes the set [A o] x .. x [An-I] .
• A value r f- V : B denotes a function [v]val : [I'] ----+ [B]
• A term r f- M : B denotes a funct ion [M ]ret : [I'] ----+ A * x [B]
T he denotations of types is given by
[beel] {t rue, fa Ise}
[A + A'] [A] + [A']
[A -+ B] [A] -+ (A * x [B ] )
The denotations of valu es-some example clau ses:
[x]val(p, X t-t x, P' ) x
[true] valp t rue
[i nl Vra'p inl [Vra'p
[Ax.M ]valp Ax .[M ret (p, x t-t x)
The denotations of returners-some example clauses:
[xret (p, x t-t x , P') (" ", x)
[truer tp (" " , true)
[inl M r et = (m, inl v) where [Mrt p = (m,v)
(m * m ' , v) if [M ]retp = (m , true )
and [N] ret p = (m' ,v)
[if M then N else N']p
{ (m * m' , v) if [M r etp = (m , fa lse)
and [N T etp = (m' ,v)
[A x.M rt p ("" , Ax .[Mrt(p , x t-t x ))
[M 'Nrtp (m * m ' * m il , w) where [Mrtp = (m , v )
and [N r tp = (m' , J) and v' j = (mil , w)
Call-By- Value and Call-By-Name 13
Noti ce how strongly these clauses resemble the corresponding clauses of
Fig. 1.2.

Proposition 2 (soundness) If M -lJ. m , V then [Mr et = (m, [v]val)


D

Corollary 3 (by Prop. 1) For any closed ground returner (i.e, returner
of ground type) M , we have M -lJ. m , return n iff [M] = (m, n). D

1.6.3 Scott Semantics


The reader may be familiar with Scott semantics for CBV . This has
appeared in two forms.
1 In the older form, types denote pointed cpos, returners denote strict
functions and values denote strict, bottom-reflecting functions.
2 In the more recent form, due to Plotkin [Plotkin, 1985], types denote
(unpointed) cpos , values denote total functions and returners denote
partial functions.
Although these two semantics are equivalent, (2) is more natural, and
it agrees with the key principle of our printing semantics: the elements
of [A] are denotations of closed values of type A. We outline the Scott
semantics in form (2)2 to make apparent its similarity to the printing
semantics.

Definition 1.2 1 A cpo (X,~) is a poset with joins of all directed


subsets.
2 A function between cpos is continuous when it preserves all directed
joins.
3 We write Cpo for the category of cpos and continuous functions.
D

The semantics is organized as follows.


• A type A denotes a cpo [A]. Our int ention is that a closed value of
type A will denote an element of [A] .
• A context r = A o, . .. ,An- 1 denotes the cpo [r] = [A o] x··· x [An- I] .
Intuitively, this is the set of environments for r , because an identifier
can be bound only to a closed value.

2We make the slight m od ification of using total fun ctions to lift ed cpo s instead of partial
functions .
14 CALL-BY-PUSH- VALUE

• For a value r I- V : A , we see t hat given an environment we obtain


(by substit ution) a closed valu e. So V denotes a cont inuous function
[v ]val from [r] to [A].
• For a returner r I- M : A , we see that, given an env ironment , we
obtain (by substitution) a closed returner , which either diverges or
returns a value of type A. So M denotes a continuous function [Ml et
from [r] to [A] -l'
The semantics of types is given as follows:
• heel denotes the flat 2-element cpo {t rue, fa15e}, because a closed
value of ty pe heel is either true or false .
• A + A' denotes the disjoint uni on of [A] and [A'] .
• A -+ B denotes the cpo of continuous funct ions from [A] to [B] -l,
because a closed value of type A -+ B is of t he form Ax.M, and t his,
when applied to a closed value of type A gives (by substitution) a
closed return er of type B.
We omit the semantics of terms.

1.6.4 The Monad Approach


We briefly mention a categorical viewpoint on CBV due to Moggi
[Moggi, 1991]. Readers unfamiliar with this viewpoint or with category
t heory may omit this section.

Products, Strong Monads, Exponentials, Distributive


Coproducts
We rev iew some categor ical definitions used in Moggi's semant ics of
CBV.
Definition 1.3 Let C be a category. A product for a fam ily of ob-
jects {Aih EJ is an object V (the vertex ) together wit h, for each i E I ,
1r;
a morphism V • Ai such t hat, for any fam ily of morphisms
X Ii . Ai , there is a unique morphism X 9 • V such t hat
for each i E I t he diagram
X

9
~ B, commutes.

V
~
Call-By- Value and Call-By-Name 15

A category with all finite products is called cartesian . D

Definit ion 1.4 Let B be a category. A monad on B consists of


• an endofunctor T on B;
• a natural transformation 'fl from idB to T;
• a natural transformation J-L from T 2 to T
such t hat t he following diagrams commute:
• T 2A
'I T A
TA T3A~T 2A

"Al, I"A T,Aj I'A


T 2A • TA T 3A • TA
/LA /LA

Given such a monad, t he Kleisli category CT has t he same objects as C; a


CT - morphism from A to B is a C- morphism from A to T B. The ident ity
on A is 'flA while the composite of A f . T B with B g . TO
is j; Tg ; J-Lc . D

Definition 1.5 Let C be a cartesian category. A strength for a monad


(T, 'fl, JI, ) on C consists of a natural transformation

AXTB~T(AxB)
such that the following diagrams commute:
1 x TA t{l, A ) • T(l x A) (A x B) x TC t(AXB,C! T((A x B) x C)

xr A

TA
/~~
/

A x (B x TC)
.> (
/ T Q(A ,B ,C)

) A x T(B x C) t (A,B x C ) T(A x (B x C))


A x t B ,C

Tt(A ,B )

,,(AxB)

t(A ,B)
16 CALL-BY-PUSH- VALUE

A monad toget her with a strength is called a strong monad. We often


refer to a st rong monad (T , n, 11, t) just as T . 0

Definition 1.6 Let C be a cartesian category. An expone ntial from an


object A to an object B is an object V (t he vertex) together with a mor-
phism V x A B such t hat, for any morphism X x A
ev • f • B
t here is a unique morphism X 9 • V such t hat

X xA

~B
g xA

V xA
.« commutes.

A cartes ian category with all exponent ials is called expone ntial. 0

The following is ad apted from [Carboni et al., 1993; Cockett , 1993].


Definition 1. 7 Let C be a cartesian category. A distributive coproduc t
for a family of objects {Ai hEI is an obj ect V (the vertex) to gether
with a morphism A i in; • V for each i E I , such t hat, for any
family of morphisms X x Ai Ii • Y , t here is a unique morphism
X xV 9 • Y such t hat for each i E I t he diagram

r:
X xV

X X Ai 9 commut es.

~Y
A cartes ian category with all finit e distributive copro ducts is called dis-
tributio e. 0

Here are some well-known resul ts about dis tributive copro duct s, ad apted
from [Carboni et al. , 1993; Cockett, 1993].
Proposition 4 Let C be a cartesian category.
1 A distributiv e copro duct for {Ad iEI must be a copro duct for { Ad iEI.
If C is cartes ian closed , t he converse is true also.

. .
IS monic.
Call-By- Value and Call-By-Name 17

3 Suppose 0 is a distributive initi al object i.e. a distributiv e copro duct


for t he empty family. Then any morphism to 0 is an isomorphism.
So parallel morphisms to 0 must be equal.
o
A cartesian closed category which is also distributive (or, equivalent ly,
whi ch has all finit e cop roducts) is called bicartesian closed.

Monad Semantics for Call-By-Value


Moggi's semantics for call-by-value is as follows. Let C be a distribu-
tive cate gory. Suppose we ar e given a st rong monad (T , 'TJ , u ; t) on C
and, for each A , B E ob C, an exponential from A to T B (this is called
a Kl eisli expone nti al ).
We then obtain a CBV model: a CBV valu e denot es a morphism of
C, and a CBV returner denot es a morphism of the Kleisli category CT.
Both of our denotational models are instan ces of t his sit uat ion. For
t he printing semant ics, C is Set and T is t he st ro ng monad A * x -
(Moggi's "interactive ou tput" monad) . For the cpo semant ics, C is Cpo
(the category of cpos and cont inuous fun cti ons) and T is the lifting
monad.

1.6.5 Observational Equivalence


Definition 1.8 A context C[· ] is a term with zero or more occur rences
of a hole [.]. If C[.] is of ground ty pe we say it is a ground context. 0

Definition 1.9 Given two te rms r I- M , M' : B , we say t hat


1 M ~ground M' when for all ground contexts C[.] , C[M ] J.l. m , z iff
C[M'] J.l. m,i
2 M ~anytype M' when for all conte xts C[.] of any ty pe, C[M] J.l. m , V
for som e V iff C[M'] J.l. m , V for some V
o
Proposition 5 The two relations ~ground and ~anytype are the same. 0

This is an important feature of CBV: it does not matter whether we


allow observat ion at ground ty pe or every typ e.
Cor. 3 implies that term s with the same denotati on are observationally
equivalent .

1.6.6 Coarse-Grain CBV vs. Fine-Grain CBV


T he form of CBV we have looked at is called coarse-grain CB V. It
suffers from two problems.
18 CALL-BY-P USH- VALUE

1 Our decision to evalua te operand before operator was arbitrary.


2 A valu e V has two denotations: [v]val and [v]ret.
We can eliminate these problems by presenting a more refined calculus
called fin e-gra in eB V in which (partially based on [Moggi, 1991]) we
make a syntactic dist inction between values an d returners. This calculus
is more suitable for formulat ing an equat ional theory. For although
Moggi in [Moggi, 1988] provided a theory for coars e-grain CBV, which he
called "Ac-calculus", this theory was not purely equat ional but required
an additional predicate to assert that a te rm is a valu e.
We will not trouble to study fine-grain CBV in this chapter, because
in the next chapte r we will present CB PV, which is even more fine-grain.
A treat me nt of fine-grain CBV and its equa t ional theory is given in the
Appendix.

1.7 Call-By-Name
1. 7.1 Operational Semantics
In CBN the following terms are terminal:

T ::= true I false I inl M I inr M I Ax.M

Every closed term M prints a string of cha racters and terminates at a


ter mina l term T . We write M -I).. m, T. This is defined induct ively in
Fig. 1.3.

Proposition 6 For every M there is a unique m , T such that M -I).. m , T .


D

The proof is similar to t hat of Prop. 10.

1. 7.2 Observational Equivalence


The denotational semant ics for CBN is more subtle than that for
CBV, so we first look a t observational equivalences.

Definition 1.10 A context C[.] is a term with zero or more occurrences


of a hole [.]. If C[·] is of ground type we say it is a ground con text . D

Definition 1.11 Given two te rms r f- M , M' : B , we say that


1 M ~ground M' when for all ground conte xts C[·], C[M] -I).. m, i iff
C[M'] -I)..m,i
2 M ~anytype M' when for all contexts C[·] of any type, C[M] -I).. m , T
for some T iff C[M'] -I).. m , T for some T .
Call-By- Value and Call-By-Name 19

N [M/ x] .ij. m ,T

let M be x. N .ij.m,T

true.ij. "" ,true false.ij. " " ,false

M .ij. m ,true N .ij. m ' ,T M .ij.m ,false N' .ij.m' , T

i f M then N else N' .ij. m * m' , T i f M then N else N' .ij. m * m' , T

inl M .ij. "", inl M inr M .ij. " " , inr M

M .ij. m, inl M ' N [M' /x].ij. m ', T

pm M a s {inl x.N , inr x. N '}.ij. m * m ' ,T


M .ij. m , inr M ' N '[M' /x] .ij. m ' , T

pm Mas {inl x.N , inr x. N'}.ij. m * m ', T


N .ij. m , Ax.N' N' [M / x] .ij. m ' ,T

Ax.M.ij."" ,AX.M M 'N .ij. m * m ' , T

M.ij. m , T

print c. M .ij. c * m , T

Figure 1.3. Big-Step Semantics for CBN with print

By cont rast with Prop. 5 we have the following.


Proposition 7 T he relation ~anytype is st rictly finer than ~ground. D

Perh aps the simplest example of this proposition is


print "hello ". Ax.M ~ground AX. (print "hello" . M) (1.4)
Obvi ously the t rivial conte xt [.J, which is not ground, distinguishes the
two sides . An intuitive explanation (not a rigorous proof) of (1.4) is
t hat, inside a ground CBN term, the only way to cause a subte rm of
type A ----7 B to be evalua ted is to apply it.
If we use divergence rat her t ha n printing, t he ana logous example is
the equivalence
diverge ~ground Xx.d.i,verge
20 CALL-BY-PUSH- VALUE

This general CBN phenomenon can be described as "effects commute


with A". Various authors studying CBN languages with only ground
types and function types have exploited it by allowing certain features
at ground type only, as the corresponding features at function type are
then definable: erratic choice [Hennessy and Ashcroft, 1980], control
effects [Laird , 1997] and conditional branching [Plotkin, 1977].
For both printing and divergence (indeed for all effects), we have, for
similar reasons, the ry-Iaw for functions: any term M of type A -+ B can
be expanded
M ':::'ground Ax.(x'M) (1.5)
where x is not in the context r of M .

1. 7.3 CBN vs. Lazy


Definition 1.12 • We use the term "CBN" (equations, models etc.)
to refer to the CBN operational semantics together with ':::'ground.
• We use the term "lazy" (equations, models etc.) to refer to the CBN
operational semantics together with ':::'anytype.
D

Thus in a CBN model the ry-Iaw (1.5) must be validated, whereas in a


lazy model (1.5) must not be validated.
Our usage of "lazy" follows [Abramsky, 1990; Ong, 1988]. However,
the terminology in the literature is not consistent, and the reader should
beware the following.
1 "Lazy" is widely used to describe call-by-need.
2 "Call-by-name" is sometimes used to mean (our sense of) "lazy" ,
especially in the continuation literature [Hatcliff and Danvy, 1997;
Plotkin, 1976] and the monad literature [Moggi, 1991].
3 In the untyped A-calculus literature, the phrase "call-by-name" is
used with a slightly different meaning from ours, and necessarily so
because there is no ground type-there is just one type and it is a
function type. In order for (1.5) to hold despite observation at this
type, a different operational semantics is used: reduction continues
to head normal form [Wadsworth, 1976].
The lazy paradigm is treated in Appendix A. We see there that it is
subsumed in CBV , so its denotational semantics is straightforward.
By contrast, in the CBN paradigm much of the big-step semantics
is not observable. For example, the two sides of (1.4) have different
operational behaviour, yet that difference cannot be observed. So a
Call-By- Value and Call-By-Name 21

denotational semantics, in order to validate (1.4) , must conceal part of


the big-step semantics. For t his reason, t he CBN paradigm is more
su btle t ha n CBV .

1. 7.4 Denotational Semantics for print


Definition 1.13 An A-set (X, *) consists of a set X together wit h a
function * from A x X to X . We call X t he carrier and * the structure.
D

Each CBN ty pe B denotes an A-set [B] = (X, *). Our intenti on is t hat
a closed term M of type B will t hen denote an element [M] of X , and
print c. M will denot e c * [M]. Thus * provides a way of "absorbing"
t he effect into X. Given an A-set (X , *) we can extend * to a fun ction
from A * x X to X in the evident way-we call t he extensio n * too. T his
extension allows us to int er pret print m. M directly.
Here are some ways of constructing A-sets.
Definition 1.14 1 For any set X , t he fr ee A-set on X has carrier
A * x X and we set c * (m, x) to be (c * m , x) .
2 For an i E I-indexed family of A-sets (Xi , *), we define t he A-set
TIiE/ (X i , *) to have carrier TIiE/ X i and structure given po intwise:
i' (c * I) = c * (i' 1) .
3 For any set X and A- set (Y, *), we define the A-s et X -? (Y, *) to have
carrier X -? Y and structure given pointwise: x' (c * I) = c * (x'l) .
D

The semantics of types is as follows:

• bool denotes t he free A-set on {t rue, false}. This is because any


closed term of type bool prints a string and then terminates as true
or false , and t his behaviour is observable.

• If [A] = (X, *) and [A'] = (X' , *) then A + A' denotes the free A-set
on X + X'. This is because any closed te rm of this ty pe print s a
string and t hen terminates as inl M or inr M , and t his behaviour
is obse rvable.

• If [ A] = (X, *) and [B ] = (Y, *) t hen A -? B denotes X -? (Y, *).


This is because any closed term of t his type is equivalent to some
>..x.M , and prefixing wit h a print command is then given by (1.4).
Given a context Xo : A o, . . . , Xn - l : A n - l , an environment consists of
a sequ ence of closed terms M« , .. . , M n - l . Writing (Xi , *) for [Ai] , t his
22 CALL-BY-PUSH- VALUE

environment denotes an element of X o x ... X X n - 1 We say that the


context denotes this set. (There is no need to retain the structure.)
Given a term r f- M : B, from any environment we obtain (by substi-
tution) a closed term of type B. So M will denote a function from [r]
to the carrier of [B].
Semantics of terms-some example clauses:

[x](p, x t---+ X, p') x


[let M be x. N] [M](p, x t---+ [N]p)
[true]p ("" , true)
[if M then N else N'] { m * [N]p if [M]p = (m, true)
m * [N']p if [M]p = (m, false)
[inl M]p ("" , inl [M]p)
m * [N](p , x t---+ a)
[pm M as {inl x.N, inr y.N'}] if [M]p = (m, inl a)
{ m * [N'](p , x t---+ a')
if [M]p = (m , inr a')
[Ax.M] Ax.[M](p, x t---+ x)
[M'N] ([M]p)'([N]p)
[print c. M]p c * [M]p
Proposition 8 (soundness) If M JJ. m, T then [M] = m * [T]. 0

Corollary 9 (by Prop. 6) For any closed ground term M (t erm of


ground type) , M JJ. m, return n iff [M] = (m , n) . Hence terms with
the same denotation are observationally equivalent. 0

Notice the sequencing of effects in the semantics of if and pm. This is


characteristic of CBN: pattern-matching is what finally caus es evaluat ion
to happen.

1. 7.5 Scott Semantics


The reader may be familiar with Scott semantics for CBN , where
types denote pointed cpos and terms denote continuous fun ctions. We
recall this semantics here , to make apparent its similarity to the printing
semantics.
Definition 1.15 A cpo is pointed iff it has a least element , which we
call ..l. We use cppo as an abbreviation for "pointed cpo" . 0

Each CBN type A denotes a cppo. Our intention is that a closed term
M of type A will denote an element of X, and if it diverges then it will
Call-By- Value and Call-By-Name 23

denote ..1. (A convergent term also may denote .1.) Thus L provides a
way of "absorbing" the effect into A.
We recall some familiar ways of const ructing cppos:

1 For a cpo X , its lift X l- consists of X to gether with an additiona l


element .1, which is below all the element s of X.

2 For an i E I-indexed famil y of cppos (Xi ' ~ '.1) the product of this
family I1i EI (Xi , ~, .1) is t he set I1i EI X i , ordered pointwis e. Its least
element is given pointwise i' .1 = .1.

3 Given a cpo (X, ~) and a cppo (Y, ~ ,.1) the expone nti al (X, ~) ----7
(Y, ~ ,.1) is the set of continuous fun ctions from (X, ~) to (Y, ~ ),
ordered pointwise. It s least elem ent is given pointwise x'.1 = .1.

The semantics of typ es is given as follows:

• boo I denot es the lift of the cpo {t rue,false}. This is because a closed
term of type boo I either diverges or terminat es as true or false ,
an d this behaviour is observable.

• If A denotes (X, ~ ,.1) and A' denotes (X' , ~ ,.1) then A + A' de-
not es the lift of the cpo (X, ~) + (X' , ~ ) . ("CBN sum denotes lifted
sum .") This is because every closed term of this type eit her diverges
or terminates as inl M or inr M , and this behaviour is observabl e.

• If A denotes (X, ~ ,.1) and B denotes (Y, ~ ,.1) then A ----7 B denotes
(X , ~) ----7 (Y, ~ , .1). T his is because every closed term M of this type
is equivalent to some Ax.N, and if M diverges then it is equivalent
to Ax.diverge.

Given a context Xo : A o, , Xn - l : A n - 1 , an environment consists of a


sequence of closed te rms M o, , M n - 1 • Writing (Xi , ~ ,.1) for [A i] , this
environment denot es an element of the cpo (Xo , ~) x . .. x (X n - 1 , ~ ) .
We say that the context denotes this cpo.
Given a term r f- M : B , from any environment we obtain (by subst i-
tution) a closed term of type B . So M will denote a cont inuous function
from [r] to [B]. We omi t the seman ti cs of te rms.

1.7.6 Algebras and Plain Maps


We cont inue the categorical dis cussion of Sect. 1.6.4. Again , t his
sect ion may be omitted by read ers unfamiliar with category t heory.
The two denotational models of CB N t hat we have seen ar e both
cartesian closed categories:
24 CALL-BY-PUSH- VALUE

• The printing semantics for CBN is the cartesian closed category in


which an object is an A-set (X, *) and a morphism from (X, *) to
(Y, *) is a function from X to Y .

• The cpo semantics for CBN is the cartesian closed category of cppos
and continuous functions.
In fact, every model for CBN must be a cartesian closed category, as it
must validate the {3- and 1]-laws for funct ions.
These two cartesian closed categories are instances of a general con-
struction, based on the notion of algebra for a monad.
Definit ion 1. 16 [Mac Lane, 1971] Let (T, 1], /-l) be a monad on a cate-
gory C. A T -algebra consists of a pair (X ,8), where X is an object ofC,
8 is a morphism from T X to X, and

-,
1)X /LX
X · TX · T 2X

0 TO (1.6)

X. TX
0

commutes. X is called the carrier and 8 the structure map of t he algebra.


D

Suppose, as in Sect. 1.6.4, that we have a distributive category C with


a strong monad T. T hen we form the categoryof "algebras and plain
maps", in which an object is a T-algebra (X,8) and a morphism from
(X,8) to (Y, ¢) is any C-morphism from X to Y . Assuming sufficient
exponentials, this category must be cartesian closed [Simpson, 1992], as
we exp lain presently.
To see that our two models are instances of this construction, notice
that
• an algebra for the A * x - monad on Set is precisely an A-set;
• an algebra for t he lift ing monad on C p o is precisely a cppo.
The interpretation of CBN in the category of algebras and plain maps
ma kes use of several ways of constructing algebras.
Defin it ion 1. 17 Let (T, 1], 11" t) be a strong monad on a cartesian cat-
egory C.
1 For an object X, the free T -algebra on X is the algebra (TX,/-lX) .
Call-By- Value and Call-By-Name 25

2 For a family of T-algebras {(Xi , Oi) hE!, suppose {Xd iEI has a given
product in C. Then the produ ct T-algebra for {(Xi , Oi)} iEI is t he
algebra with carrier IT iEIXi and t he obvious st ructure map.
3 For a C-obj ect X a nd T- algebra (Y,O), suppose there is a given ex-
ponential in C from X to Y. Then the expon en ti al T- algebra from
X to (Y,O) is the T -algebra with carrier X -T Y and structure map
corresponding to
{J
X x T(X -T Y) tx,x ---t ~ T(X x (X -T Y)) ~ TY - -- -. Y

o
We can see how to interpret CBN types using these construct ions, and
that our constructions of cppos and of A-sets ar e sp ecial cases. For ex-
ample, the boolean type denotes the free algebra on 1 + 1. If A denotes
(X, 0) and B denotes (Y, ¢) t hen X -T B denotes t he exponent ial algebra
from X to (Y, ¢). It is now easy to see that if exponent ials to carriers of
T -algebras always exist- which implies, by the way, that Kleisli expo-
nentials exist- then t he category of algebras and plain maps is cartesian
closed .
We emphasize t hat in t he ca tegory of algebras and plain maps, an
object is an algebra (X , 0) , not just a C-object X on which t here exists a
st ruct ure map O. Although t his lat ter definition would give a cartes ian
closed ca tegory equivalent to our s, it would not give a semant ics of CBN.
To see t his, look at the sema nt ics for pm: it uses t he spec ific structure O.
In summary,
a CBV ty pe den ot es an object of C; a CBN ty pe denot es aT-algebra.
We are not claiming that eve ry model of CBN arises from a monad
in this way, just that the printing model and the Scott mod el do .

1.8 Comparing CBV and CBN


Because CBN satisfies the ,B-law and "l-law for functions , it is some-
times suggested that CBN is "mat hema tically better behaved but prac-
ti cally less useful" than CBV. While the claim about the practical infe-
riority of CBN is valid, the claim about its mathematical superiority is
not valid.
For alt hough the CBN fun ction typ e is mathematically supe rior to the
CBV fun ction typ e, the CBN sum type (and boolean ty pe ) is inferior
to t he CBV sum ty pe . We saw that in the printing semant ics the CBV
sum simply denotes the sum of sets , while t he CBN sum denotes a more
complex construction on A-sets. Similarly, in t he Scott semantics, t he
sum of cpo s is a mu ch simpler const ruction t han the lifted sum of cppos.
In particu lar, t he CBV sum is ass ociative whereas t he CBN sum is not .
26 CA LL-BY-PUSH- VALUE

T his sit uation is seen not j ust in denotational semantics but also in
equat ions. Consider t he following equ ivalence-a special case of t he "1-
law for bool. If M has a free identifier z : boo 1 then

M = if z t hen M[t r uejz] else M[f al s ejz]

holds in CBV but not in CBN . It hold s in CBV because z can be bound
only to a value, true or false . It fails in CBN because z can be bou nd
to a term such as print "hel l o". true.
T hus , t he perception of CBN 's supe riority is act ua lly due to t he fact
t hat function ty pes have been considered more impor tant , and hence
have received more attention, t ha n sum ty pes or even gro und ty pes .
A consequence of t his bias (towards fun cti on ty pes and towards CBN)
has bee n t he promotion of cartesian closed category as a significant
st ruc t ure , in the semantics of programming languages and even in t he
semantics of intuitioni stic logic. T he lat ter is especially inapp ropriate,
because t he type t heory to which int uiti onisti c logic corresponds is effect-
free rather t ha n CBN or CBV, so its models must be bicartesian closed
categories.
Chapter 2

CALL-BY-PUSH-VALUE:
A SUBSUMING PARADIGM

2.1 Introduction
2.1.1 Aims Of Chapter
In this chapter we present the CBPV language and its operational
and denotational semantics for our example effects of printing and di-
vergence, and we show how it contains both CBV and CBN. Operational
semantics is presented in two forms : the familiar big-step form and the
CK-machine of [Felleisen and Friedman, 1986].
We will introduce the following vocabulary, all of which will be used
in subsequent chapters :

• value , computation, terminal computation

• value type, computation type

• thunk, forcing a thunk

• configurat ion, stack

• sequenced computation, returner , cont inuat ion.

We suggest the following slogans and mnemonics.

• A value is, a computat ion does.

• U types are t hUnk types, F types are returner types.

• For cpos, U means nUthing, F means "liF t" .

27
P B Levy, Call-By-Push-Value
© Springer Science+Business Media Dordrecht 2003
28 CA LL-B Y-PUSH- VA LUE

2.1.2 CBV And CBN Lead To CBPV


Becau se we have used print ing rather t ha n divergence as our lead ing
example of an effect, our exploration of CBV and CB N lead s us na turally
to t he types of CBPV. As we explained in Sect. 1.2, in t he printing
sem an tics, a CBV ty pe denot es a set whereas a CB N typ e deno tes an
A-set. Thus we will need two disjoint classes of ty pe in t he subsuming
language: ty pes denoting sets and ty pes denoting A -sets. These are
precisely the valu e typ es and computation ty pes (respectively) of CBPV.
Furthermore, t he subsuming language should provide typ e constructors
correspo nding to the various ways we have seen of const ructing A-sets,
and CBP V indeed does this. For example,
• FA denotes the free A-set on [A]
• UB denotes the carrier of [B] .
Inventing the term calculus of the subsuming language is not as eas y
as t he ty pes, but we can obtain helpful guidelines by recalling equational
facts about CBV and CBN and t he informal reasons for t hem.
• In CBV , t he l1-law for sum ty pes (and bo olean ty pe ) holds because
identifiers are bound to values.
• In CBN , t he l1-law for fun cti on ty pes holds because a te rm offunct ion
ty pe can be mad e to evaluate only by applying it .
We would like our subsuming language to have both of t hese properties,
a nd ind eed CBPV does.

2.2 Syntax
The typ es of CBPV (as st ated in Sect . 1.5.4) are given by

A ::= UB I I:iEIAi I1 IAxA


B ::= FA I TI i EI B i I A -1 B
where each set I of tags is finit e. (We will also be concerned with
infinitely wide CBPV in which I may be countably infinite-see Sect. 4.1
for more discussi on.) We will ofte n write i for a par ti cular eleme nt of I .
We usually omit terms, equations et c. for the type 1, becau se it is just
t he nullar y analogue of x.
Since identifiers can be bound only to valu es, they must have value
typ e. So we have t he following:
Definition 2.1 A context r is a finite sequence of identifiers with value
types Xo : A o, ... , Xn - I : An- I . Sometimes we omit t he identifiers and
wr ite r as a list of value types. 0
Call-By-Push- Value: A Subsum ing Paradigm 29

The calculus has two kinds of judgement


r f-c M : B r f-v V : A

for computat ions and values respectively. We emphasize that , in each


case, only value types appear on the left of f-. The terms of basic (i.e.
effect-free CBPV) are defined by Fig. 2.1. We will freely add whatever
syntax is required for the various computational effects that we look at .

r f-v V : A r ,x : A f-c M : Ii

r , x : A, r ' f-v X : A r f-c let V be x. M : Ii

r f-v V : A r f-c M : F A r, x : A f-c N : Ii

r f-c return V : FA r f-c M to x. N : Ii

r f-c M : Ii r f-v V : U e
r f-v thunk M : UIi r f-c force V : 11

r f-v V : A i r f-v V : E iEIAi ... r ,x : Ai f-c Mi : Ii . . . iEI

r f-v (i , V) : E iEI A i r f-c pm V as {. .. , (i ,x) .Mi , .. .} : Ii

r f-v V : A r f-v Vi : A' r f-v V : A x A' r , x : A, y : A' f-c M : Ii

r f-v (V, V') : A x A' r f-c pm V as (x , y) .M : Ii

... r f-c M, : Iii .. . iEI r f-c M : ITiE1Ii i

r f-c i' M : 11i

r ,x : A f-c M : Ii r f-v V :A r f-c M : A -+ Ii

r f-c Ax.M : A -+ 11 rf-cV'M :Ii

Fig ure 2.1. Terms of Bas ic Lan guage

Definition 2.2 1 A returner is a computation of ty pe FA.


2 A ground type is a ty pe of the form 2:iEll (su ch as bool = 1 + 1).
3 A ground value is a valu e of ground typ e.
4 A ground returner is a computation of type F A, where A is a ground
type.
We write true and false for the closed valu es of typ e bool = 1 + 1
and i f V then M else M' for the corresp onding pm construct. 0
30 CALL-BY-PUSH- VALUE

Notice t hat CBPV has two forms of product. In the terminology


of Sect . 1.3.2, the product of value types is a pattern-match product
whereas the product of computation types is a proj ection product. The
reason we do allow a term 7fV where V has type A x A' is that the
CBPV operational semantics (presented in Sect. 2.3) exp loits the fact
that values do not need to be evaluated. So we cannot allow a compl ex
valu e such as 7f(t r ue , false ), which needs to be evaluated to true.
Complex values are discussed fully in Chap. 3.

2.3 Operational Semantics Without Effects


Although at this stage we give t he language without effects , we take
care that the definit ions, propositions and proofs can easily be adapted
to vario us effects where possible.

2.3.1 Big-Step Semantics


The big-step semantics has t he form M .JJ. T , where M an d Tare
closed computations of the same type, and T is terminal, meaning that
it belongs to t he following class:

T ::= return V I A{ .. . , i.Mi , . . . } I Ax.M

The big-step ru les are given in Fig. 2.2.

Proposition 10 For every closed computation M , there is a un ique


terminal computation T such that M .JJ. T. 0

Proof( in the sty le of [Tait , 1967]) We define, by mutua l induct ion over
types, three fam ilies of subsets:

• for each A, a set red'A of closed values of type A

• for each B , a set redh of terminal computations of type B

• for each B , a set redl! of closed computations of type B.

These definition of these subsets proceeds as follows:


Call-By -Push- Value: A Subsuming Paradigm 31

M[V/x] JJ- T
l e t V be x. M JJ- T

M JJ- return V N[V/ x] JJ- T


return V JJ- return V M to x. N JJ- T

M JJ- T
force thunk M JJ- T

Mi[V/ x] JJ- T
pm (i, V) as { . .. , (i, X).Mi' . . .} JJ- T

M [V/x , V ' fy ] JJ- T


pm (V, V ') as (x , y ).M JJ- T

M JJ- A{ . . . , i .Ni' . . .} N i JJ- T


A{.. . , i .Mi" " } JJ- A{.. . , i .Mi" . ' } 1,' M JJ- T

M JJ- Ax.N N[VIx] JJ- T


Ax.M JJ- Ax.M V 'M JJ- T
Note that each of these rules is of t he form
M o JJ- To Mr- 1 JJ- T r - 1
(2.1)
M JJ- T
for some r ~ O.

Figure 2.2. Big-Step Semantics for CBPV

thunk M E red B u iff M E red ~


(1" V) E red~ ~. iff V E redr ,
LJi EI t
(V, V') E red'A xA' iff V E red'A and V ' E red'A,

return V E red ~ A iff V E red'A


A{. .. , i.u; ...} E redt
Ax.M E red~-t~
n«. i -«B. iff
iff
M, E red? B i for all i E I
M[V/x] E redlr for all V E red'A

M E redlr iff M JJ- T for unique T , and T E redh


32 CALL-BY-PUSH- VALUE

Notice t hat if T E 1['B , t hen T E red -~ iff T E redk


-
. F inally we show t hat
• for any computation A o, ... , A n - 1 f-c M : B , if W i E redA; for i =
------+ C
0, . . . , n - 1 t hen M[Wi! xi] E redli
• for any value A o, . . . , A n - l f-v V : B , if W i E redA. for i = 0, .. . , n-1
------+ '
then V [Wi! Xi] E redB.
T his is shown by mutual induction on M and V , and gives the requ ired
result. 0

2.3.2 CK-Machine
T he CK-machine is a general form of operational semantics that can
be used for CBV and CBN as well as for CBPV. It was int roduced
in [Felleisen and Friedman, 1986] as a simplification of La ndin's SECD
mac hine[Landin, 1964], and there are many simi lar machines [Bierman,
1998; Krivine, 1985; Streicher and Reus , 1998]. At any point in time,
the machine has configuration M , K when M is the term we are eval-
uating and K is a stack' . There is no need for an environment or for
closures, because substitution is used . To incorporate types, we write a
configuration of the machine as
M K

where B is t he type of the cur rent computation M and C is the type of


the initial computation (so C stays fixed during execution).
The machine is summariz ed in F ig. 2.3. Let us ignore the types for
the moment, and understand the mac hine by thinking about how we
might implement the big-step rules using a stack.
Suppose for example that we are evaluating M to x. N. The big-
st ep semantics te lls us that we must first evaluate M . So we p ut the
context [.] to x. N onto the stack, because at present we do not need
it. Later, havin g evaluated M to return V , we can remove [.] to x. N
from t he stack and proceed to evaluate N[VIx], as t he big-step semant ics
suggests.
As another example, suppose we are evaluating V 'M . T he big-step
semantics te lls us that we must first evaluate M. So we put the operand/

1 When Felleis en and Fr iedman converted t he ir CK-mach ine into a small-step semantics , t hey
introd uced t he te rm evaluation con text for stack; bu t t he C K-mach ine see ms eas ier an d mor e
natural to wor k with . We use t he te rm ino logy curre nt stack rather t han current con tinu ation
beca us e in C BP V (unlike CBV) not all stacks are continua tions: for exa m ple, t he stack V :: K
is a pa ir , not a cont inuation -see DeL 2.5. We look at t his in mo re de tail in Sect . 5.4.5.
2If we wa nted ou r us age to be strictly consistent, we wou ld put the cont ext V' [.] rather than
j ust V onto t he stack, bu t t h is is un necessa ril y com plicated .
Call-By-Push- Value: A Subsuming Paradigm 33

V onto the stack, because at present we do not need it. Later, having
evaluated M to Ax.N, we can remove the operand V from the stack and
proceed to evaluate N[VIx], as the big-step semantics suggests.
To evaluate a closed computation M, we place it alongside the empty
stack nil and follow the transitions in Fig. 2.3 until we reach a configu-
ration T, nil for a terminal computation T. We shall see in Sect. 2.3.6
that this will happen precisely when M JJ. T.
Notice that
• the behaviour of V'M is to push V and then evaluate M
• the behaviour of Ax.M is to pop V and then evaluate M[VIx]
From the big-step rules we have thus recovered the push/pop reading
described in Sect. 1.5.1, although we did not mention there that the stack
is used for sequencing as well as for operands.

2.3.3 CK-Machine For Non-Closed Computations


Whereas big-step semantics is suitable only for closed computations,
the CK-machine can be quite naturally extended from closed computa-
tions to computations on a fixed context r. This extension will be useful
for studying control effects, where, as we see in Sect. 5.4.3, we will want
to treat the empty stack nil as a free identifier.
A configuration of the machine now takes the form

r M B K c (2.2)

and both rand C stay fixed during execution. The transitions are
entirely unchanged, and we need only give some additional terminal
configurations, which try to force or pattern-match a free identifier. The
details are shown in Fig. 2.4.

2.3.4 Typing the CK-Machine


Given a configuration of the CK-machine

r M B K C

we know that r I-c M : B, but we do not as yet have a way of typing the
stack K. We therefore introduce a judgement fiB I- k K : C to achieve
this task. This judgement means that K is a stack that accompanies a
computation of type B in the course of executing a computation of type
C, with free identifiers given by r . The typing rules for this judgement
are immediate from Fig. 2.3 and Fig. 2.4, so the reader is invited to write
them out. The solution is given in Fig. 2.5.
34 CALL-BY-PUSH- VALUE

Initial Configuration To Evaluate f-c M : C

M C nil C

Transitions

let V be x. M B K C
M[Vj xJ B K C
"'"
M to x . N B K C
"'" M FA [.J to x . N :: K C

return V FA [.J to x . N :: K C
N [Vj xJ B K C
"'"
force thunk M B K C
M B K C
"'"
pm (i , V) as {. .. , (i , x).Mi , "'} B K C
"'" M dVj xJ B K C

pm (V, V ') as (x , y ).M B K C


M[Vjx , V 'j yJ B K C
"'"
i' M B·
-t
K C
M TIiEIB i i :: K C
"'"
A{... .i.Ms, .. .} TIiEIB i i :: K C
Mi Bt· K C
"'" -

V 'M B K C
M A-+B V ::K C
"'"
Ax.M A-+B V:: K C
M[Vj xJ B K C
"'"
Terminal Configurations

return V FA nil FA
A{ ... ,i.M i, .. .} TIiEI B i nil TIiEIB i
Ax.M A-+B nil A-+B

Figure 2.3. CK-Machine For CBPV , Wi th Typ es


Call-By-Push- Value: A Subsum ing Paradigm 35

Initial Configuration To Evaluate r f-c M : C

r M nil

Transitions

As in Fig. 2.3 but with r before each line

Terminal Configurations

r return V FA nil FA
r A{... ,i.Mi , . . .} TIiEIBi nil TIiEIB i
r Ax.M A---+B nil A---+B
r ,z : UB ,r' force z B K C
r ,z : E iEIAi, r' pm z as { .. . ,i.Mi, " ' } B K C
r ,z : A x A' , r' pm z as (x, y).M B K C

Figure 2.4. CK-Machine For Non -Closed Computat ions

r ,x : A f-c M : II fill f-k K :Q


flC f-k nil : C rIPA f-k [.J to x. M :: K : C

rlBi f-k K : C r f-v V : A rill f-k K :Q


flA ---+ B f-k V :: K : C

Figure 2.5. Ty ping St acks

Definition 2.3 A configurat ion from r to C consists of


• a computation typ e B
• a computat ion r f-c M : B
• a st ack riB f-k K :C
o
Proposition 11 (determinism) For every configuration Q from r to
C , pr ecisely one of the following holds.
1 Q is not te rminal, and Q ""'"' Q' for unique configuration Q' from r to
C.
36 CALL-BY-PUSH- VALUE

2 Q is terminal, and there does not exist Q' such that Q -v-+ Q'.
D

To complete the CK-machine semantics, we write -v-+* for the transitive


closure of -v-+. More technically:
Definition 2.4 We define inductively the relation -v-+* on configura-
tions:
M' K' -v-+* N L
, '(M K -v-+ M' K')
M,K-v-+* M,K M,K-v-+* N , L ' ,
D

By analogy with Prop. 10, we can now formulate the following.


Proposition 12 For every configuration Q from I' to C there is a
unique terminal T (which is also from I' to C) such that Q -v-+* T ,
and there is no infinite sequence of transitions from M, K. D

The only nontrivial part is the last part, and we defer the proof of to
Sect. 7.5.3.
Definition 2.5 (complementary to Def. 2.2(1)) A continuation is a
stack from a type FA to any type. D

Such a stack uses the value that a returner returns. For example,
[.J to x. N :: K is a continuation. (This usage of "continuation" is
consistent with the CBV literature, because in CBV, every stack is a
continuation, just as every computation is a returner.)

2.3.5 Operations On Stacks


There are 3 operations on stacks which are of great importance in the
theory of CBPV. (Of course, they are just as important in the theory of
CBV and CBN, when one considers stack terms for these paradigms.)
substitution We can substitute values for free identifiers in a stack K,
just like in a computation or in a value.
concatenation Given a stack qA I- k K : B and a stack qB I- k L : C ,
we can concatenate them to obtain riA I- k K *L : C.
dismantling A stack riB I- k K : C can be dismantled onto a compu-
tation I' I-c M : B giving a computation I' I- c M • K : B. Informally,
this is obtained by running the CK-machine in reverse on the config-
uration M, K, reducing the stack until it is empty.
Formally, each of these is defined by induction on K. The reader can
easily write out all the clauses, so we do not present it until Fig. 10.2.
Call-By-Push- Value: A Subsuming Paradigm 37

2.3.6 Agreement Of Big-Step and CK-Machine


Semantics
The sale aim of this section is to prove
Proposition 13 For closed computat ions M , T of type B , the following
are equivalent:
1 M J.l.T;
2 M,K ",,",* T , K for every stack K such that B f-k K : C for some C ;
3 M ,nil ",,", * T ,nil.
D

(1) ::::} (2) is a straightforward induction. (2) ::::} (3) is trivial.

Lemma 14 For all M and N of type B , if, for all T , M J.l. T implies
N J.l. T, then , for every B f-k K : C , we have that C , M. K J.l. T implies
N.K J.l.T. D

Proof Induct on K. D

Lemma 15 If M , K ",,",* T , nil t hen M. K J.l. T . D

Proof We induct on the antecedent. As an example clause, suppose that


the antecedent is given by

return V, [.J to x. N:: K """' N [V / x]' K ",,",* T ,nil

We know by the inductive hyp othesis that (N[V/x]) • K J.l. T , so by


Lemma 14 we know that (return V to x. N) • K J.l. T . D
Prop. 13((3)::::}(1)) is an immedi ate consequence of Lemma 15.

2.4 Operational Semantics for print


We now add printing: more precisely, we add to the syntax of CBPV
the typing rule
r f-c M : B
r f-c print c. M : B
and we must adapt the operational semantics accordingly.

2.4.1 Big-Step Semantics for print


Since we have added only one term constructor to the basic language,
we might expect that we need only add one rule to Fig. 2.2. However ,
this is clearly not possible: whereas for t he basic lan guage the big-st ep
38 CALL-BY-PUSH- VALUE

relation has the form M .lJ. T , it now has the form M .lJ. m , T . It seems
ther efore that we must present the big-step semantics from scratch.
Fortunately this is not the case. We simp ly replace each rule in Fig. 2.2
of the form (2.1) by
Mo.lJ. mo ,To
M .lJ. mo * ... * m r-l, T
Then we add the big-step rule
M.lJ.m ,T
print c. M .lJ. c * m , T
Proposition 16 For every comp utat ion M , ther e exists unique m , T
such that M .lJ. m , T. 0

T he proof is eas ily adapte d from the proof of Prop. 10.

2.4.2 CK-Machine For print


In Fi g. 2.3 a t rans it ion has t he form (om itting the typ es)
M K M' K' (2.3)
With print ing , we want a transition t o have the form
M K m M' K'
wh ere m E A*. So we replace each transition (2.3) in Fig. 2.3 by
M K 1111
M' K'
and we add t he t ransit ion
print c. M K c M K

We replace Def. 2.4 by the followin g.


Definition 2.6 We define t he relat ion "",*, whose form is M , K "", *
m , M' , K' inductively:
M' K' "",* n N L
, " (M,K "'" m ,M' ,K')
M ,K "", * III1 , M ,K M ,K "",* m * n ,N,L
o
We can st ate and prove analogues of all the results in Sect . 2.3.4-2.3.2.
In particular we have
Proposition 17 M .lJ. m , T iff M , nil "",* m , T , nil. o
Call-By-Push - Value: A Subsum ing Paradigm 39

2 .5 Observational Equivalence
As with CBV and CBN, we want to define a noti on of observational
equivalence.

Definition 2.7 1 A ground con text is a closed ground returner with


zero or mor e occurrences of a hole whi ch might be a computation or
a value.

2 Given two computations r f-c M, N : B , we say that M ~ N when


for every ground context C[.] we have that C[M] -U- T iff C[N] -U- T (for
every T) . We sim ilarly define ~ for values .
o

We modify t his to sui t t he effect being consid ered. For printing (with-
out divergence) we say t ha t M ~ N when for every ground context C[.],
we have that C[M] -U- m , T iff C[N] -U- m , T (for every T) .

2.6 Denotat ional Se mant ics


2.6.1 Values and Computations
In the printing semantics, a valu e ty pe (and hence a context ) den otes
a set , and a computation type denotes an A-set . The semant ics of ty pes
is given by

[UB] the carrier of [B]


[LiE/A i] L iEI [Ai ]
[A x A'] = [A] x [A']

[FA] the free A-set on [A]


[IliEIBi] IliE1[B i ]
[A -T B] [A] -T [B]

Simil arly we defin e the denotation of a context I' : if r is t he sequence


A o, . .. , An- I, then we set [r] to be the set [A o] x ... x [An- d .
Next we define the semant ics of te rms. A valu e r f-v V : A denotes
a fun ction [V] from the set [r] to t he set [A], and a computation r f-c
M : B denot es a fun ction from the set [r] to t he carrier of the A-set
40 CALL-BY-PUSH- VALUE

[B]. Here are some example clauses:


[return V]p (1, [V]p)
[M to x. N]p m * [N](p, x f---7 a) where [M]p = (m, a)
[thunk M]p [M]p
[force V]p [V]p
[Ax.M]p AX.[M](p, x f---7 x)
[V 'M]p ([V]p)'([M]p)
[print m. M]p m * ([M]p)
In the Scott semantics, a value type denotes a cpo and a computation
type denotes a pointed cpo. Some example clauses:

[UB] [B]
[FA] lift of [A]
[A -+ B] [A] -+ [B]
Like a value type, a context denotes a cpo , given by x. Then a value
r f-V V : A denotes a continuous function [V] from the cpo [r] to the
cpo [A], and a computation I' f-c M : B denotes a continuous function
from the cpo [r] to the pointed cpo [B].
Notice that, in both printing and Scott semantics, the constructs
thunk and force are invisible in the sense that

[thunk M] [M]
[force V] [V]
In the Scott semantics, U too is invisible, meaning [UB] = [B]' By
contrast, in many of the semantics in Chap. 5 thunk ,force and U are
all visible.

Proposition 18 (Soundness of Denotational Semantics) For any


closed computation M, if M -u. m, T then [M] = m * [T]. D

Corollary 19 (by Prop. 10) For any closed ground returner M , we


have M -u. m, return n iff [M] = (m, n) . Hence terms with the same
denotation are observationally equivalent. D

If we are dealing with non-closed computations as in Sect. 2.3.3, then


Prop. 18 extends to
Proposition 20 For any computation r f-c M : B and any environ-
ment p E [r] if M -u. m, T then [M]p = m * ([T]p) . D
Call-By -Push- Value: A Subsuming Paradigm 41

2.6.2 Denotational Semantics Of Stacks


All of the denotational semantics for CBPV considered in t his book
interpret not just values and computat ions, bu t stacks too. (It is this
t hat makes the ca tegorical semant ics in Part. III so simple.) For exam-
ple, let us consider the 2 models we have studied so far. Suppose we
have a stack fiB f-k C .
• In the Scott mod el, K denotes a continuous fun ction f from [r] x [B]
to [C] satisfying f(p ,..1) = ..1 i.e. it is strict in its second argument.
• In the printing model, K denotes a funct ion f from [r] x [B ] to [C]
satisfying f (p, c * x ) = c * f (p, x) i.e. it is homomorphic in its second
argument.
We omit t he equations giving the interpretation of each term constructor;
they are straightforward.

2.6.3 Monads and Algebras


We now return to the monad semantics of Sect. 1.6.4 (CBV) and
Sect. 1.7.6 (CBN) ; this secti on can be omitted by the non-categorical
read er. We are goin g to interpret stacks as algebra homomorphisms,
defined as follows.
Defini tion 2.8 Let (T , TI , j1. , t) be a strong mon ad. AT-algebra homo-
morphism from aT-algebra (Y,O) to aT-alg ebra (Z, ¢) over a C-object
X is a C-morphism X x Y f • Z such that

X x T Y ~ T(f x Y) ~ TZ

X xO ¢ commutes.

X xY - -- - - - - ---+
. Z
f
o
As in Sect . 1.7.6, suppose we have a strong monad T on a distributive
category C, with an exponential from A to B whenever B is the carrier
of a T -al gebra. We t hen interpret
• a value type (and hence a context ) by a C-obj ect
• a computat ion typ e by a T -a lgebra
• a value I' f-v V : A by a C-morphism from [f ] to [A]
42 CA LL-BY-PUSH- VALUE

• a com putation I' f-c M : B by a C-morphism from [f] to t he carrier


of [B] (again, t his makes thunk and force invisible)

• a stack fiB f-k 0 by a T -algeb ra homomorphism from [B] to [0]


over [f].

It is easy to see t hat t his generalizes t he Scott semantics and printi ng


semantics . In part icular, a homom orphism b etween cp pos is a strict
continuo us function .

2.7 Subsuming CBV and CBN


We give t rans la t ions fro m t he CBV and CBN fragmen t s described in
Chap. 1. The full translati on s and t he ir t echnical proper ti es (adequacy,
full abs t ract ion etc .) are given in Appendix A.
If the reader b ears in mind the denotational semantics of CBV and
CBN, t he t rans lations into CBP V are obv ious .

2.7.1 From CBV to CBPV


T he big difference b etween CBV and C BPV is t hat in CBV Ax.M
is a value whereas in CBPV Ax.M is a computation . T hus AX in CBV
decomposes int o thunk AX in CBPV.
More generally, a CBV funct ion fro m A to B is, fro m a CB PV p er-
spective, a t hu nk of a computation t hat pops a value of ty pe A and
returns a value of ty pe B. So we have a decomposit ion of -+ C B V into
CB PV given by
A -+ C B V B = U(A -+ F B) (2.4)
It is import ant to see t hat t his decomposit ion respects both of our deno-
tat ional semantics i.e. t he two sides of (2.4) have t he same den ot ati on .
This is essent ia l if t he translation is to b e regarded as subsum ptive.

• In t he printing semantics, A -+ F B den otes an A- set wh ose carrier


is t he set of fun ct ions from [A] to A* x [B]. So t he thunk type
U (A -+ F B) denot es t his set, as does A -+ C B V B .

• In t he Scot t semant ics A -+ F B den ot es t he cp po of continuo us


fun ctions fro m [A ] to [BlL . So t he t hunk type U(A -+ F B ) den ot es
t his cpo, as does A -+CB V B .

The translation fro m CBV to CBPV is presented in F ig. 2.6. Just


as a CBV value V has two de notations [v]val and [v] ret, so it has two
translations vval and V prod re lated by

v prod = return Vval


Call-By-Push- Value: A Subsuming Paradigm 43

c C V (a value type)
bool bool i.e . 1 + 1
A+B A V
- s:
A--+B U(A V --+ FB V )
Ao, . . . , A n - 1 f- V : C AoV , .. . , A n_ 1V f-v Vval : CV
x x
true true
false false
inl V inl Vval
inr V inr Vval
Ax.M thunk Ax.Mprod

A o, . .. , A n - 1 l- M : C
x return x
let M be x. N l\1 prod to x. Nprod
true return true
false return false
if M then N else N' Mprod to z . if z then Nprod else N,prod
inl M Mprod to z . return inl z
inr M Mprod to z . return inr z
pm M as {inl x.N, inr x.N'} Mprod to z . pm z as {inl x.Nprod, inr x.N,prOd}
Ax.M return thunk Ax.Mprod
M 'N Mprod to x. Np rod to f . x'(force f)
print c. M print c. Mprod

Figu re 2.6. Tr anslation of CBV types, valu es and returners

in the CBPV equational theory of Chap. 3.


As we explained for -+CBV, the translation preserves denotational
semantics. Thus, for both printing and Scott semantics, we have the
following:
Proposition 21 1 For any CBV type A, [A]cBV = [Av]cBPV .

2 For any CBV value r f- V : A, [V]ckv = [vval]CBPV.

3 For any CBV returner r f- M: A , [M]ckv = [Mprod]cBPV.


o
That the translation resp ects operational semantics (to a certain de-
gree of intensionality) is proved in Appendix A.

2.7.2 From CBN to CBPV


The translation from CBN to CBPV is motivated as follows.
• Identifiers in CBN are bound to unevaluated terms, so we regard
them (from a CBPV perspective) as bound to thunks.
44 CALL-BY-PUSH- VALUE

• Similarly, tuple-components and operands in CBN are un evaluated


ter ms, so we regard t hem as t hunks .

• Consequently, identi fiers , t up le-compo nents and operands all have


type of t he form UB - a t hunk type.
We t hus have a decom position of -7 C B N into CBPV .

A -7 C B N B = (UA) -7 B (2.5)

It is important to see t hat t his decompositi on respects bot h of our de-


notational semantics i.e, both sides of (2.5) have t he same denotation.
This is essent ial if t he translation is to be regard ed as subsumptive.
• In t he printing semant ics, if A denotes the A-set (X, *) and B denot es
t he A-set (Y, *) t hen U A denot es t he set X and (U A) -7 B denot es
X -7 (Y, *), as does A -7CBN B.

• In t he Scot t semanti cs, (U A) -7 B denotes t he cppo of cont inuous


fun ctions from [A] to [B] , as does A -7CBN B.
Simil arly we have decompositions

boolcBN F b ool
A + CBNB F ((U A) + (U B ))
It is easily seen t hat these also respect denot ational semantics, e.g. t he
Scott semant ics for F (( U A) + (U B )) is t he lift ed sum of [A ] and [B ].

e en (a com put ation ty pe)


bool F b ool i.e. F (l + 1)
A+B F( UA n + U B n)
A -+B (UA n)-+ B n
Ao , ... , A n - 1 f- M : e UAo , ... ,UA ~_l f-c M'" : en
x force x
let M be x . N let thunk M " be x. M "
true return true
false return false
if M then N else N ' M " to z . if z then N" else N ,n
inl M return inl thunk M"
pm M as {inl x.N , inr x.N'} M" to z . pm z as {in l x .N" , inr x .N ,n}
>..x.M >..x. M n
N 'M (t hunk N n)'M n
print c. M print c. M"

Figure 2. 7. Trans lation of CBN ty pes and te r ms


Call-By-Push- Value: A Subsum ing Paradigm 45

As we explained for -+CBN , the translation preserves denotational


sem antics. Thus, for both printing and Scott semant ics, we have the
following :
Proposition 22 1 For any CBN type A , [A]cBN = [An]cBPY.
2 For any CBN te rm r f- M : A , [M]cBN = [Mn]cBPY .
D

That the translation resp ects op erational semantics (to a certain degree
of intensionality) is proved in Appendix A.

2.8 CBPV As A Metalanguage


We can use CBPV not just as an obj ect language but as a met a-
language. When we do this, we have to spec ify whi ch CBPV model
the metalanguage is referring to. For example, when t alking about t he
printing model, we use FA to refer to the free A-set on the set A , and
U B to refer to the carrier of the A-set B .
Another example is the Scott model.
• If A is a cpo we write FA for its lift , a cppo.
• If a E A we write return a for the corresponding element of FA.
• If bE FA and f is a fun ction from A to a cppo B , we wri te b to x, f( x)
to mean ..1 if b = ..1 and f(a) if b = return a.
• If B is a cppo, we write U B to mean the cpo B.
• If bE B we write thunk b for b regarded as an element of UB.
• If a E U B we write force a for a regarded as an element of B .
It may seem superfluous to write U , thunk and force when referring to
the Scott model, because they ar e invisible. But the advantage of doing
so is that everyt hing we write in t his notation is meaningful not just in
the Scott model but in any CBPV model.

2.9 Useful Syntactic Sugar


2.9.1 Pattern-Matching
It is convenient to exte nd all const ructs that bind identifiers to allow
pat tern-matching. We give some examples.

sugar un sugar ed
M to {. . . , (i, x) .Ni , .. . } M to z . pm z as {.. . , (i, x) .N i , . . . }
A(x,y).M Az.(pm z as (x, y) .M)
pm M as (w, (x , y)). N pm M as (v, z).(pm z as (x, y). N)
46 CALL-BY-PUSH- VALUE

We use such abbreviations only informally, as it would be complicated


to give a precise, general description.

2.9.2 Commands
The types Fl and FO have a special significance in CBPV, because
they can be seen as types of commands, as we now explain.
Computations of type Fl are commands such as printing, assignment,
divergence and so on . They correspond to terms of type COmIn in Idealized
Algol [Reynolds, 1981], and to returners of type unit in ML. Such a
command can be prefixed to a computation of any type. We write

return for return 0


print c for print c. return 0
M iN for M to O. N

(The command return is written skip in Idealized Algol, CSP etc .)


The typing rules for these constructs are as follows.

r f-c M : Fl r f-c N : B
r f-c return: Fl r f-c MiN : B

r f-c print c : Fl

Computations of type FO constitute a more restricted class of com-


mands, the nonreturning commands such as divergence or raising an
error. Such a command can be coerced into a computation of any type.
Since a nonreturning command ignores its continuation", we can say in-
tuitively that any two stacks from FO to C are equivalent, for any C.
(Indeed, they will be provably equal in the equational theory of Chap. 3.)
We write
coerce JiM for M to {}
ignored for [.J to {} :: nil

We will make use of FO for technical purposes in Sect. 7.8.2, so we take


the trouble here to describe explicit ly the typing rules for its constructs.

r f-c M: FO
r f-c coerce e M : B fiFO f-k ignored : C

3T h is would not be the ca se if we considered exception handling, bu t we do not.


Call-By-Push- Value: A Subsuming Paradigm 47

2.10 Computations Matter Most


We have seen that CBV terms and CBN terms are translated into
CBPV computations. One generally finds that the computation judge-
ment is the most important in CBPV-the role of values and stacks is
an auxiliary one. Thus many results, especially definability results, are
really results about computations.
Consider, for example, a definability result stating that every com-
putable element of, say, a domain model or a game model is the deno-
tation of an appropriately typed term [Hyland and Ong, 2000; Plotkin,
1977; Sazonov, 1976]. Such a result can be true only for the computation
judgement, because it is impossible for every computable total function
f : N --+ N to be the denotation of a value x : nat f-v V : nat, written
in a finitary syntax.
Other examples in this book of a result which concerns only com-
putations (actually for the J ump-With-Argument language rather than
CBPV) is Prop. 79, and the domain enrichment in Sect. 9.5.5.
Sometimes we shall extend a language by adding more value and stack
constructs. But we prove that every computation M in the larger lan-
guage is equal (in some appropriate equational theory) to a computation
N in the smaller language. We shall call this a computation-unaffecting
extension. Because the two languages have the same computations, we
shall regard them as essentially the same.
The principal example of this procedure occurs in the next chapter,
where we add complex values and complex stacks to CBPV, so that the
equational theory we describe can be shown (in Chap. 10) to have a
simple categorical semantics. Unfortunately, the simplicity of the opera-
tional semantics is lost as a consequence. At that point , the reader may
protest:
Surely this is cheating! You claim that CBPV has all these good properties.
But which CBPV? For the CBPV (with complex values) that has a simple
categorical semantics is different from the CBPV (without complex values)
that has a simple operational semantics.
This objection is answered when we show that the extension is computation-
unaffecting, so that the languages are essentially the same.
Chapter 3

COMPLEX VALUES AND EQUATIONAL


THEORY

3.1 Introduction
In t his cha pter we look at 2 equationa l t heories, as shown in Fig. 3.1.
All t he extensions ar e computation-unaffecting in t he sense of Sect. 2.10.

programming language CK-machine e q u atio n a l theory

CBPV ~ CBPV
+ complex valu es
1 conservative

CBPV + stack~ CBPV + stacks


+ com plex values

Figure 3.1. Var iet ies of CBPV

We first see that , in order for the equationa l theory to have reasonable
mathemat ical prop erties (in particular, categor ical semant ics), we need
to add in Sect. 3.2 some ext ra te rms called com plex value s for the L:
an d x ty pes .
We present an equationa l theory for CBPV with complex valu es in
Sect. 3.3. Unfortunately, t here is no reversible derivat ion for F . We
use t his t heory in Sect. 3.5 to show t hat addi ng complex values is
computation-unaffecting.
We t hen look present an equational t heory for CBPV with stacks . As
well as complex valu es, t his requires complex stacks for t he IT and -7
types (t hese ar e roughly dual to t he com plex values) . T his equational

49
P B Levy, Call-By-Push-Value
© Springer Science+Business Media Dordrecht 2003
50 CALL-BY-PUSH- VALUE

theory is much better behaved: it has reversible derivations for all the
connectives. We use it to construct some isomorphisms between types.
Finally, we will look at how this theory is related to effect-free equa-
tional theories.

3.2 Complex Values


Suppose we want to form a value x : bool f-V not x : bool. This
seems reasonable: it makes sense denotationally, and a natural way to
code it is i f x then false else true. But the CBPV syntax as defined
in Fig. 2.1 will not allow this, because the rules allow pattern-matching
into computations only, not into values. (Recall from Sect. 2.2 that if
is the pattern-match construct for bool = 1 + 1.) A similar problem
arises with values such as w + 5 and x + y, which we used in our example
program in Sect . 1.5.2.
For another example-and one which which will be indispensable
when we come to equational/ categorical issues, because it gives us a
cartesian category of values-try to form a value x : bool x nat f-V 1TX :
bool. Again, this makes sense denotationally, and a natural way to
code it is pm x as (y, z). y. But this too involves pattern-matching into
a value.
All these are examples of complex values. We incorporate them into
the CBPV language by adding the rules in Fig. 3.2.

r f-v V : A r, x : A f-v W : B
r f-v let V be x. W : B

r f-v V: l:iEIAi .. . r,x: Ai f-v Wi: B ... iEI


I' f-v pm V as {... , (i, x). Wi , . . .} : B

r f-v V: A x A'r, x: A, y : A' f-v W : B


I' f-v pm V as (x, y) .W : B

Figure 3.2. Complex Values

All these rules make sense in every denotational model, and, as we


mentioned above, they are indispensable when we study equational/categorical
issues. The reader may therefore wonder: why did we not include these
rules from the outset? The answer is that excluding complex values
keeps the operational semantics simple: both our big-step and our ma-
chine semantics exploit the fact that values do not need to be evaluated.
Complex Values and Equational Theory 51

Furthermore, the range of the transforms from CBN and (coarse-grain)


CBV into CBPV does not involve complex values .
It would certainly be possible to extend the operational semantics to
include complex values, but at the cost of canonicity. We would have to
make an arbitrary decision as to when to evaluate complex values. Since
the evaluation of complex values causes no effects, the decision has no
semantic significance. We will therefore continue to exclude complex
values when treating operational issues, but otherwise we will include
them.
We shall see in Sect. 3.5 that adding complex values is computation-
unaJJecting in the sense of Sect. 2.10: a computation containing complex
values can be converted into one without. For example,

return (if x then false else true)

can be converted into

if x then return true else return false

Less importantly, complex value constructs can also be removed from a


closed value.

3.3 Equations
In Sect. 2.1 we looked at equational properties of CBV and CBN, and
the informal reasons for them:

• In CBV, the 1']-law for sum types (and boolean type) holds because
identifiers are bound to values.
• In CBN, the 1']-law for function types holds because a term offunction
type can be made to evaluate only by applying it.

We stipulated that a subsuming language should have both of these


properties. We can now see that CBPV indeed meets these requirements.
• Identifiers are bound to values, so the 1']-laws for sum types holds.
• A term of function type can be made to evaluate only by applying it ,
so the 1']-law for function types holds.
The equational issue is more immediately apparent from a denotational
perspective, whether we look at the printing semantics or the Scott se-
mantics:
• In CBPV, [A + AI] is precisely the disjoint union of [A] and [AI] -
like in CBV but unlike in CBN.
52 CALL-BY-PUSH- VALUE

• In CBPV [A] -+ [B ] is precisely t he set of fun ctions (or t he cpo of


continuous functions) from [A] to [B] - like in CBN but unlike in
CBV.
We thus formulate an equa tional theory for CBPV (with complex
values) , given in Fig 3.3. M , Nand P range over computa tions, while
V and W range over values. Q ranges over all terms, both computations
and valu es.
The equations for print and diverge ar e of cour se sp ecific to our ex-
ample effects, but there are directly analogous equations for many other
effects. We call this theory (without t he print and diverge equations)
the CBP V equational theory.
For both print ing and Scott models we have (as a consequence of a
substit ution lemma, which we omit)
Proposition 23 Provably equal te rms have the same denotation. D

3.4 CK-Machine Illuminates ---+ Equations


We recall from Sect. 1.5.2 and Sect . 2.3.2 t ha t AX and V ' can be read
as commands:
• AX means "pop X"
• V ' means "push V " .
This read ing illumina tes many equations involving -+ (as well as t he
analogous equat ions involving IT). Here are some examples.
1 Consider the equat ion
print "he llo". Ax.M = Ax.(print "hello". M) (3.1)
In the CK-machine reading , the LHS means
print "he l l o" .
pop x.
M
while the RHS means
pop x.
print " he l l o" .
M

Provided t he stack is non -empty (as it must be if the initial con-


figuration was ground) , th ese two behaviours ar e t he sam e, because
popping and print ing do not int erfere.
Comp lex Values and Equa tiona l Theory 53

f3-la w s
let V be x. Q Q[V/ x]
pm (i , V) as { . . . , (i, X).Qi , . . .} Qi[V/ X]
pm (V, V') as (x , y). Q Q[V/ x , V ' / y]
force thunk M M
(r e t ur n V) to x. M M[V/ x]
i' ..\{.. . ,i.Mi, ... } Mi
V '..\x.M M [V/ x]

1]-law s
M M to x. return x
V thunk force V
Q[V/z] pm V as { .. . , (i, x) . X(J [(i, x) / z], ... }
Q[V/z] pm V as (x, y). xYQ[(x, y)/z]
M ..\{. . . ,i .i' M, ... }
M ..\x.(x ' XM)

sequencing laws
(M to x. N) to y. P M to x. (N to y. XP)
M to x . ..\{ . . . . i.Ni , .. .} ..\{... ,i.(M to x. Ni) , ... }
M to x. ..\y.N ..\y.( XM to x. N )

print laws
(pr i nt c. M) to x. N print c. (M t o x. N)
print c. ..\{ . . . ,i.Mi, ... } ..\{ .. . ,i. (pr i nt c. M) , ... }
print c. Xx.M ..\x.(print c. M)

di verge laws
diverge to x. N diverge
diverge ..\{ ... , i. di ve r ge , . .. }
diverge ..\x.d i ve r ge

Figure 3.3. CBPV equations , using convent ions of Sect . 1.4.2

2 In t he f3-1aw
V '..\x.M ~ M[V/ x]
t he LHS means
push V.
pop x.
M
54 CALL-BY-PUSH- VALUE

The first two lines have the effect of binding x to V and leaving the
stack unchanged, so the overall effect is to obey M with x bound to
V.

3 In the 1]-law
M ~ AX.(X' XM)
the RHS means
pop x.
push x.
M - which does not mention x

Assuming again that the stack is non-empty, the first two lines have
the effect of leaving the stack unchanged and binding x to the top
entry in the stack. But we are assuming that x is not used in M, so
the binding is of no consequence.
4 The analogue of (3.1) for divergence is

diverge ~ Ax.diverge

The RHS means


pop x;
diverge
Assuming again that the stack is non-empty, this diverges.
As an aside, we notice that all these 4 equations, and the push/pop
reading that explains them, hold in CBN as well as in CBPV. Indeed,
Krivine at one point adopted the operand-first notation, for just this rea-
son [Krivine, 2001]. Therefore, "call-by-push" would have been a good
name for CBN. The name "call-by-push-value" for our new language re-
flects the fact that it is a value that gets pushed during application, not
a general term as in CBN.

3.5 Adding Complex Values is


Computation-U naffecting
Lemma 24 If M = N is provable and M and N do not contain complex
values then M ~ N . 0

Proof This follows from Prop. 23 and Cor . 19. 0


We are now in a position to see that complex values can be eliminated
from a computation, as required. As a bonus, we can also eliminate
complex values from a closed value.
Compl ex Values and Equational Theory 55

Proposition 25 1 There is an effect ive procedure that , given a com-


putation I' f-c M : B , possib ly containing complex valu es, returns a
computation I' f-c M : B without complex values , su ch t hat M = M
is provable.

2 There is an effective procedure that , given a closed value f-v V : A,


possibly containing complex values, retu!ns a closed valu e f-v V : A
without complex values, such that V = V is provabl e.
o
Proof

1 We will define one su ch procedure, and simultaneously, for each value


r f-v V : A, possibly containing complex values, and each complex-
value-free computation r , v : A f-c N : B , we will define a complex-
value-free computation I' f-c N[V// v] : B such that N[V//v] = N [V/v]
is provable.
By mutual induction on M and V , we define M and N[V//v] III
Fig. 3.4 and we prove t he equat ions

M=M
N [V// v] = N[V/ v]

2 For a valu e Ao, . . . , An- 1 f-V V : A poss ibly containing complex val-
ues, we will define V to be a fun ction that, when applied to a sequence
Wo, . . . , Wn- 1 of complex-value-free closed valu es f-v Wi : Ai, returns
a complex-value-free closed value V(Wo, .. . , Wn-d such that
- --+
V(Wo, ... , Wn-d = V [Wi!xi]
is provable. This is defined by induction on V in Fi g. 3.4. The special
case n = 0 gives the desir ed result.
o
By choosing some such procedure, we can extend the operational se-
mantics to include gro und returners with complex values: if M is such
a returner, we say tha t M JJ. m , i iff M JJ. m , i . Becaus e of Lemma 24,
this relation do es not depend on the choice of pro cedure . ::.. .
We can adapt the proof of Prop. 25 to show that complex values can be
removed from a context . So it is immaterial whether , in our definition of
observational equivalence, we allow contexts to contain complex valu es.
We can extend Prop, 23 and Cor . 19 as follows, for the printing lan-
guage :
56 CALL-BY-P USH-VALUE

v N [V // v]
x N [x / v]
let W be x. U (let I/' be x. N[Uflv])[Wfll/']
(i , W) (let (i,l/') be v. N )[W // I/']
pm Was {.oo ,(i,X).ui , oo .} (pm I/' as {. . . , (i, X) .N[Uiflv], . . .})[Wfll/']
(W ,W') (l e t (I/' , x) be v. N )[W // I/'][W' fix]
pm Was (x, y).U (pm I/' as (x , y).N[U//v]) [Wfll/']
thunk M N [t hunk if/ v]
M if
let W be x. N (let I/' be x. N )[W fll/']
pm W as {oo . ,(i,x) .Ni , oo .} (pm I/' as {oo ., (i, x) .Ni ,oo .})[W fll/']
pm Was (x, y).N (pm I/' as (x , y).N) [W//I/']
A{oo . , i.Ni , oo .} A{oo . , i.Ni , oo .}
i'N i'N
Ax.N Ax.N
V 'N (v'N)[Vflv]
return V (return v)[V flv]
N to x. P N to x. P
force V (force v)[V//v]
print c. N print c. N

V V(~)
Xi Wi
let W be x. U [r(~, W(~))
(i , W) (i , W(~))
pm W as {oo . , (i, X).ui , . oo } Ut ( ~ V ') where W(~) = (i , V')
(W,W') (W(Wi ) , WI ( ~))
pm Was (x , y).U [r( ~ , V' , V " ) where W(~) = (V ' , V" )
- ----':--t
thunk M thunk M [Wi / X;)

Figure 3.4. Definit ion s used in proof of Prop. 25

Proposition 26 Provable equality implies denotat ional equa lity, which


implies observational equivalence . D

This adapts to the various effects and denot ational models we will look
at.

3.6 The Problem With the CBPV Equational


Theory
T he equational theory of Fig. 3.3 is convenient for reasoning about
equivalence of programs, and we have seen that it fits well with the
CK-machine reading. Bu t it is flawed in two ways.
1 There is no revers ible derivation (in the sens e of Sect. 1.3.4) for F .
Compl ex Values and Equational Th eory 57

2 As we saw in Sect . 2.6.2, the denotational models we st udy are typi-


cally able to interpret st acks as well as values and computations. So
we would like an equat ional theory that can reason about equality
for st acks.

Fortunat ely, these problems are solved together . We will formulate an


equational theory for CBPV with stacks, conservat ively exte nding that
of Fig. 3.3, and see that it has reversible derivations for all the connec-
tives , including F .

3.7 Complex Stacks

r I-V V : A r , x : A I-v W : B r I-v V : A r ,x.AIH.l-k K : Q


I' I-v let V be x. W : B qB I-k let V be x. K : C

I' I-v pm V as {. . . , (i , x) .Wi , .. .} : B

r I-v V : L iEIA i . . . r , x : AilH.l- k K i : Q ... iEI


qB I-k pm V as {. . . , (i , x) .Ki , . .. } : C

r I-v V : A x A' r , x : A , y : A' I-v W : B


r I-v pm Vas (x ,y).W: B

r I-v V : A X A'r, x: A , y : A'IH.I- k K : Q


qB I-k pm V as (x , y) .K : C

q Q I-k K : II rl H. I-k L : I2
qc I-k K where nil is L : D

q Q I-k K i : H.i ... iEI qrriEIH.i I-k L : I2


qc I-k {•••, K, where i :: nil, ... } is L : D

r , x: AIQ I-k K : H. qA -+ ll l-k L : I2


qc I-k K where x :: nil is L : D

Figure 3.5. Complex Values and Stacks


58 CALL-BY-PUSH- VALUE

Just as we have to add complex values to get a well-behaved equational


theory, we also have to add complex stacks, shown in Fig. 3.5. These
new constructs are of two kinds. Firstly we want to be able to pattern-
match (or bind) a value V into a stack, just as we can pattern-match V
into a computation or a value. These are the let and pm rules.
Secondly we want to be able to pattern-match or bind a stack, and
this requires some explanation. The idea is that if we have a stack K to
B, the symbol nil that appears on the right is rather like an identifier,
because it can be replaced by a stack L from B, giving the concatenated
stack K * L. So it makes sense to be able to bind nil to L . We could
perhaps write such as binding as let nil be L. K. But we have chosen
instead the syntax K where nil is L, as this agrees with the order of
concatenation.
Now suppose we have a stack L from A -+ B. Typically, this is of
the form V :: L' , where V is a value of type A and L' is a stack from B.
So we can pattern-match L , suggesting the syntax pm L as x :: nil. K.
Again, we choose the more convenient syntax K where x :: nil is L.
Similarly, a stack L from TIiEIBi is typically of the form i: : L', where
L' is a value from B i . So we can pattern-match L, suggesting the syntax
pm L as {i :: nil. Kd. Again, we choose the more convenient syntax
{. . . .K, where i :: nil, ... } is L, although unfortunately this is difficult
to read as English.
Since a stack is never a subterm of a computation or a value, we do
not require an eliminability theorem, such as we had for complex values
(Sect. 3.5) . But we do need to extend to complex stacks the definition
of dismantling and concatenation; this is given explicitly in Fig. 10.2.

3.8 Equational Theory For CBPV With Stacks


Now that we have introduced both complex values and complex stacks,
we are in a position to give the equational theory for CBPV with stacks.

The equations for print and diverge are of course specific to our
example effects, but there are directly analogous equations for many
other effects.
One noteworthy equation of Fig. 3.6 is the 'T]-law

M. K = M to x. ((return x). K) (3.2)

This is equivalent to the two equations

M M to x. return x (3.3)
(M to x. N). K M to x. (N. K) (3.4)
Complex Values and Equational Theory 59

,B- Iaw s
let V be x. Q Q[V/x]
K where nil is L K*L
pm (1;, V) as {... , (i, X).Qi ," '} Qi[V/X]
pm (V, V') as (x, y) .Q Q[V/x, V' /y]
force thunk M M
(return V) to x. M M[V/x]
i''x{. .. , i .M i" " } u,
{ .. . .K; where i :: nil, .. .} is i: : L K i*L
V ''xx .M M[V/x]
K where x :: nil is V :: L K[V/x]*L

7]-laws
Q[V/z] pm V as {.. . , (i, x). X(J [(i, x) / z], ... }
Q[V/z] pm V as (x, y) . xYQ[(x, y)/z]
V thunk force V
M.K M to x. ((return x) • XK)
K*L [.] to x. ((return x) • XK) :: L
M 'x{. . . , i. i' M, . . .}
K*L {... , (K * i :: nil) where i :: nil , .. .} is L
M 'xx.(x ' XM)
K*L (XK *x :: nil) where x :: nil is L

print law
(print c. M) • K = print c. (M. K)

diverge law
diverge. K diverge

Figure 3.6. Equa t iona l laws for CI3PV + st acks, using op erations of Sect . 2.3.5

As instances of (3.4) we have the sequ encing laws of Fig. 3.3. Similarly
the print and diverge laws of Fig. 3.3 are instances of the print and
diverge laws of Fig. 3.6.
It is thus evident that our equational t heory for CBPV+stacks ex-
tends our CBPV theory. What is not apparent at this stage is that the
exte nsion is conservat ive. We prove this in Appendix B.
60 CA LL-B Y-PUSH- VAL UE

3.9 Reversible Derivations


Now that we have an equationa l t heory for CBP V + stacks, we can
ask what revers ible derivati ons it poss esses, and we see in Fig. 3.7 t ha t
it possesses ru les for each connective, including F .

Rules for X

r f-v A r f-v A'


Rules for 2:= r f-v A x A'

r,Ai f-v B .. . iE I r , A , A ' f-v B


r , 2:=i EI A i f-v B r ,A x A' f-v B

... r , A i f-c 11 . . . iE I r " A A' f-c -B


r , 2:= i EI A i f-c B r , A x A' f-c -B
I' , A-IB
l _ f-k _C ... l'EI r , A , A' III f-k Q
r ,A x A' IB f-k C
Rules for U Ru les for F

Rules for IT Ru les for -t

r f-c lli ... iE I r ,A f-c 11


r f-c IT i E1B i r f-c A -t B

r iG f-k
_ B l· ... l'EI
- r , AIQ f-k 11
rj C f-k A -t B

Figure 3. 7. Reversible deri vations for CBPV with stacks


Complex Values and Equat ional Theory 61

3.10 Example Isomorphisms Of Types


We frequently want to say that two CBPV typ es are "isomorphic" .
Her e are some examples:

A -+ (B -+ C) ~ (A x B) -+ C (3.5)
UA x UA' ~ U(A n A') (3.6)

(3.5) is t he cur rying isomorphism. Operationally, this says that pop-


ping two op erands su ccessively is essent ially the same as popping a pair
of operands.
(3.6) says that a pair of thunks can be coalesced into a single thunk,
of a computat ion that first pops a binary tag and proceeds accordingly.
These isomorphisms are obviously valid in bo th the printing model
and the Scott model. Here is a syntacti c definition:
Definition 3 .1 value type An isomorphism from A to B is a pair of
values x : A f-v V : B and y : B f- W : A such that V[Wjx] = y and
W[Vjy] = x are provable.
computation type An isomorphism from A to B is a pair of st acks
IA f-k K : B and IB f-k L : A su ch that K -tt- L = nil and L-tt- K = nil
are provable.
o
It is then eas y to construct the desired isomorphisms (3.5)-(3.6). As a
consequence we have
Proposition 27 Every CBPV type is isomorphic to a typ e canonical
fo rm , meaning a typ e in the following class:

A.,= 'LiE/UBi
B.,= lliE/(UB i -+ FA i)
o

3.11 Trivialization
T he effect-free language analogous to CBPV is the x 'Lll -e-calculus
shown in Fi g. 3.8; essent ially this is the Abool-l-calculus of Sect. 1.3
extended with both pattern-match products and projection products.
As t his calculus is effect-free, it is not necessary to have both kinds of
product , just convenient .
We use the term "x -calculus" for t he frag ment of this calculus using
just x ; similarly " x 'L-calculus" and so forth .
It is easy to see that we can collapse effect-free CBPV + stacks, with
complex values and complex stacks, into the x'Lll -e-calculus. T his
62 CALL-BY-PUSH- VALUE

Types

A ::= 1 I A x A I L:iE/ A i I IT iE/ A i I A -+ A


where each set I is fini te (or countable, for infinitely wid e x L: IT -+-calculus)

Terms

rl- M: A r , x :A I-N: B

r ,x : A , r ' I- x: A I' I- let M be x . N : B

r I- M : A r I- M ' : A' r I- M : A x A ' r , x : A , y : A' I- N :B

r I- (M , M' ) : A x A' r I- pm M as (x, y ).N : B

I' I- M : Ai r I- M : L:iE/Ai ... r, x : A i I- N, :B ... iE /

I' I- pm M as {. . . , (i ,x).N i , . .. } : B

... r I- M; : B; .. . i E/ r I- M : IT iE/Bi
I' I- A{.. . , i.M« , . . .} : ITi E/Bi r I- r u . s,
r , x :A I-M : B rl- M : A r l- N : A -+B

r I- Ax .M : A -+ B r I- M 'N : B
Equations , u sing conventions of Sect. 1.4.2

.a- la w s
let M be x . N N[M/ x]
pm (M , M') as (x, y ).N N[M/ x ,M' / y]
pm (i, M) as {. . . , (i , X).N i , .. .} N i [M/ x]
i' A{ . . . , i.Mi , . . .} Mi
M ' AX.N N[M/ x ]
17- la w s
N [M / z ] pm M as (x, y ).N[ (x , y)/z]
N [M / z ] pm M a s { , (i, x ).N[ (i , x)/z], .. .}
M A{ , i .i' M, . . .}
M Ax. (x ' M )

F igure 3.8. T he x L: IT -+ -Calculus

t ransform of equat iona l t heories is called tri vialization. It discards U


and F and leaves all ot her ty pe constructors un changed. It translates

• a value I' f-v V : A to a term I'" f- V t r : A t r

• a computation I' f-c M : B to a te rm I'" f- M " : B t r


Complex Values and Equational Theory 63

We omit the actual translation of terms, which is entirely straightfor-


ward.
It follows that every model for x LIT ---+-calculus (in categorical terms,
a bicartesian closed category-Sect. 1.6.4) gives a model for CBPV (a
trivial model).
In the opposite direction, we can translate xL-calculus into CBPV
with complex values-just regard everything as a value . Consequently,
every CBPV model must include a model for xL-calculus (in categorical
terms, a distributive category-Def. 1.7) for interpreting values. We call
it the value category of the CBPV model.
II

CONCRETE SEMANTICS
Chapter 4

R E CURSI ON AND INFINITELY DEEP CBPV

This chap ter does not dep end on Ch ap. 3.

4.1 Introduction
This cha pter is abo ut t he computational effect of di vergence. There
is lit tle origina l work here; our aim is to recall and adapt well-known
material , whi ch is not specific to CBP V, for use in subsequent chapters ,
notabl y our treatment of t hunk storage in Sect . 6.10.
F irst, we add recursion to CB P V- bot h rec urs ive te rms and recursive
ty pes -and look at t he denot ational semant ics.
Secondly, we look at a lan guage feature t hat is, in a sense, equivalent
to recursion-infinitely deep synt ax. This mean s t ha t t he parse t ree of a
term or ty pe can be infinitely deep , i.e. branches can be infinitely long.
Bohm trees are a well-known example of su ch te rms. Our only subse-
quent use of infinitely deep CBPV will be to state definability results
for game semantics in Cha p . 8.
It is important not to confuse this infinitely deep syntax with the
weaker feature of infinit ely wide syntax , which is used throughout the
book. The latter simply means that we allow types L:i E/Ai and ITi E/ B i '
where I is countably infini te. (Therefore, parse t rees of typ es and terms
are infinitely wide.) Infinitely wid e syntax does not introduce divergence
into the language, and all t he CBPV semantics in t he book can int erpret
it . It provides, for example, an easy way of giving a ty pe of natural
numbers: as L:i EN 1. We use it also as a metalan guage while describing
t he possible world semantics in Chap. 6.
It is easy to see that once we allow infinit ely deep syntax, we can en-
code infini tely wide syntax- for example, t he infinitely wide ty pe L:i EN1

65
P B Levy, Call-By-Push-Value
© Springer Science+Business Media Dordrecht 2003
66 CA LL-BY-PUSH- VA LUE

ca n be written as t he infinitely deep type 1 + (1 + (1 +... )). In summary :

finitary infinitely wid e infinitely deep


CBPV C CBPV C CBPV

Of course, all of t his applies equally to CBV or to CBN .


There is a serio us problem t hat arises from both infinitely wide and
infinitely deep syntax- non-computability . For example, when we define
nat to be l:iEN1 , eve ry function ! from N to N is definable, even if ! is
not computable:

I- C Xx.pm x as {. . . i. r et ur n !(i) , . . .} : nat -7 F nat

Consequently realizability mo dels of CBPV (which we do not treat in


t his book) are not models of eit her infin itely wide CBP V or infinitely
deep CBP V. This can probably be remedie d by restrict ing infinitely deep
CBPV to "comp utable terms" and "effectively prese nte d ty pes" , as is
done for st rategies and arenas in game semant ics (e.g. [Hyland an d Ong,
2000]). However , we have not investigated t his.
In t he fina l sect ion of this chapter, Sect. 4.8, we see how we can see
how to restrict our interpretat ion of CBPV in cpo and cppos to a smaller
class of predomains and domains. We emp has ize t hat t his would not be
poss ible for a language prov iding a -7 ope ration on value types.
The material in Chap. 3 on complex valu es and the equa tional t he-
ory is not , at present , applicable to infinitely deep CB PV. We do not
have an appropriate notion of congruence needed to define an equational
theory, an d we need an equational theory to justi fy the addit ion of com-
plex values, by showing the extension to be computation- unaffecting.
Creating such an equational theory remains a challenge for future work.
In part icular , it would be desirable to have a form of pattern-matching
in complex values sufficient ly power ful to construct a syntactic isomor-
phism between j.lX.(bool x X) and O.

4.2 Divergence and Recursion


Alt hough we have already described t he Scott model of CBP V in
Sect . 2.6, t he model is rather po intless if we do not add rec urs ion to t he
language. We now look at this addit ion .

4.2.1 Divergent and Recursive Terms


We add to t he basic CBPV language t he constructs

r , x: U.!1l-c M :.!1
r I-c diverge : B r I-c ux.M : B
Recursion and Infinitely Deep CBPV 67

While diverge is not strictly necessary (e.g. it can be desugared as


u x.i ox c« x) it is convenient to include it as a primi tiv e.
We add the big-step ru les
diverge -l,l. T M[thunk /.Lx.MIx] -l,l. T
diverge -l,l. T /.Lx.M -l,l. T
T he rule for diverge can of course never be applied , so it is technically
dispensable. We have included it to reflect t he ope rationa l idea of diver-
gence: to evaluate diverge , one evaluates diverge, and so fort h. We
say t hat M diverges iff there do es not exis t T such that M -l,l. T. (This
definit ion is acceptable only in a deterministic setting.)
To t he CK-mac hine we add transit ions :
diverge K
-v-+ diverge K

/.Lx .M K
-v-+ M[t hunk /.Lx.Mlx] K

We exte nd t he cpo/cppo denotational sem anti cs in Sect . 2.6 by inter-


preting diverge as -1.- and interpreti ng /.L as a least pre-fixed po int, in
t he usu al way.

Proposition 28 Let M be a closed computation.


Soundness If M -l,l. T t hen [M ] = [T ] .
Adequacy If M diverges t hen [M] = -1.-.
o
Proof (in t he sty le of [Tait , 1967]) Soundness is straightforward. For our
adequacy proof, we say that a subset R of a cpo B is admissible when
R is closed un der directed joins. We say t hat R is lift-reflecting when
a, b E R and return a ~ return b imply a ~ b. Of course, in t he Scott
model, every subset is lift- reflecting, but we use t his condition so t hat
our proof generalizes to other (C p o-enriched) mod els where t hat may
not be t he case.
We define, by mu tual induction over types, three families of relations:
• for each A, a relation ~ A between [A] and closed values of type A,
such that {a E [A] la ~ A V } is admissib le and lift-reflecting
• for each B a rela tion ~ ~ between [B ] and terminal computations of
ty pe B , such t hat {b E [ B ]lb ~ t T} is admissible and contains -1.- .
68 CA LL-BY-PUSH- VALUE

• for each B a relati on :::;;~ between [B ] and closed comp utations of


typ e B , such t hat {b E [B ] lb :::;;c M} is admissible and contains ..1
The defini tion of t hese relations pro ceeds as follows:
a ~UB thunk M iff force a ~'k M
a ~~ A . (i, V) iff a = (i, b) f or some b ~A i V
LJ i E I '
a ~A xA' (V,V ' ) iff a = (b, b' ) for some b ~A V and b' ~ AI V '

b ~~ A return V iff b = ..1 or b = return a for some a ~A V


I ~tI1 . B . A{. . .
,E I - ,
.c.u. ....} iff i E I implies i'l ~ ~i M ;
I ~~ -->1f Ax . M iff a ~A V implies a'l ~Q. M [V/ x]

b ~~M iff b = ..1 or , for some T , M .ij. T and b ~h T


Notice t hat for te r mi nal T , b ~ ~ T iff b ~h T . Finally, we show t hat
• for any comput ati on A o, ... , A n - 1 f-c M : Jl, if a, ~A i W i for i = 0, . . . , n - 1
t hen [M]X i I-t a\ ~Q. M [W;j x:]
• for an y value A o , . .. , A n -
-----.,.-t
1 f-v V : B , if ai ~A .

W i for i = 0, ... , n - 1 t hen
[V]Xi I-t a\ ~B V [W ;jx;].
This is shown by mutual in du ct ion on M and V , and gives t he req uir ed res ult . 0

Corollary 29 For any closed ground returner M , we have M .lJ. return n


iff [M] = return n, and M diverges iff [M] = .L. Hence terms with t he
same denotation are observationa lly equivalent . 0

4.2.2 Type Recursion


Bot h value types and computat ion ty pes can be defined recursively,
so we exte nd t he type expressions as follows:
A ··= ... I X I J.l X.A (4.1)
B "= ... I K I J.lK·B
Here are some examples of CBPV recursive ty pes:
J.lX.(l + bool x X) finite list s of booleans
J.lK. F(l + bool x UK) finite or infinite lazy lists of booleans
Not ice again t he flexibili ty of CBP V; it can descri be both eager and lazy
recurs ive ty pes .
T here is a synt act ic difference between t he two kinds of recurs ive ty pe:
r f-v V : A [J.l X.A/ X] r f-v V : J.lXA r , x: A [J.lX.A / X] f-c M : Ii
r f-v fold V : J.l X.A r f-c pm V as fold x. M : B

r f-c M : Ii[J.lK.Ii/K] r f-c M : J.lK. B


r f-c fold M : J.lK.B r f-c unfold M : B [J.lK.B / K]
Recurs ion and Infi nitely Deep CBP V 69

T he reaso n we have not inclu ded a construct unfold V ,where V has


ty pe p, X.A, is t hat it is a complex value, and so would complicate t he
ope rationa l semantics, as explained in Sect . 3.2. If we allowed pat tern-
matching into values, as we do in Sect. 3.2, t hen unfold V could be
coded as pm V as fold x. x.
For big-step semantics, we first exte nd t he class of termina l comp u-
tations
T "= ... I fold M
and t hen add the following ru les:

M [Vl x] JJ. T
pm fold V as fold x.M JJ. T

M JJ. fold N N JJ. T


fold M JJ. fold M unfold M JJ. T

To t he CK-mac hine for CBPV we add


pm fold V as fold x.M B K C
"""' B M[Vl x] K c
unfold M B[p,X.BI X] K c
"""' M p,X.B unfold [.] :: K C

fold M p,X.B unfold [.] :: K C


"""' M B [p,X.B lx] K c
and the addit iona l terminal configuration

fold M c nil C

This necessi tates an addit ional typing rule for st acks:

I'I/J,X.B f-k unfold [.] :: K : C

4.3 Denotational Semantics Of Type Recursion


4.3.1 Bilimit-Compact Categories
In order to give denot ati onal semant ics for recur sive typ es, we first
have to review some key result s abo ut solution of domain equations from
[P itts, 1996; Smyth and Plotkin, 1982]. Whilst t hose pap ers work with
70 CALL-BY-PUSH- VALUE

the category Cpo ! of pointed cpos and strict cont inuous functions , ev-
ery t hing generalizes 1 to bil imit-compact categories , as we now describ e.
Much of this mater ial is implicit in [Stark, 1996].

Definition 4.1 Let C be a Cpo-enriched category (Le. a category


whose homset s are cp os and in which composition is cont inuous).
An (e, p) -pair from A to B consists of mo rphisms
e
A , 'B
p

such that e;p = idA and p; e ~ idE . We ca ll e an em bedding and p a


proj ection- they determine eac h other. We wr it e Cep for the category
with the same ob j ects as C, and (e,p)-pairs as morphisms.
:E Let D be a direct ed diagram in C ep i.e, a functor from a direct ed
poset ID to C eP. A cocone from D cons ists of an ob ject V (the vertex)
together with, for each d E ID, an (e,p)-pair (ed,Pd) from Dd to V ,
such that

'" fb
Dd Ddd' , D d'

for d ~ d' commute s in Cep .

'
:0 ,~
'::.I ~b

V
Such a cocone is an bilimit wh en

V(Pd; ed) = idv (4.2)


dEl!)

(It is clear t hat Pd; ed is monotone in d, so t he join has to exist .)


D

Many properties and alt ernative definitions of bilimits are given III
[Smyth and Plot kin , 1982J.

Definition 4.2 An bilimit- compaet category C is a Cpo-enriched cate-


gory with the following properties.
• Each hom-cpo C(A , B) has a least element ..1.

1 Another generalization is t o t he "rat ional categories" of [Abramsky et al., 1994], but t hey
are for ca ll-by-na me .
Recursion and Infinitely Deep CBPV 71

• Composition is bi-strict.

1-;g 1-
j; 1- 1-

• C has a zero object i.e, an object wh ich is both initial and terminal.
(Because of hi-strictness, just one of these properties is sufficient.)

• every diagram D of (e,p)-pairs indexed by a countable directed poset


1I)) has an bilimit .

o
As we sha ll see in Sect. 4.3.3, t his is sufficient structure to solve domain
equations. Here are some exa mples of bilimit- compact categories.
Proposition 30 1 The category Cpo': is bilim it-compact.

2 If C is bilimit-compact then so is Cop.

3 Any small product Ili Ef Ci of bilimit-compact categories is bilimit-


compact.

4 Let J be a small Cpo-enr iched category. (In particular, it could be a


small ordinary category-just regard the homsets as flat cpos.) IfC is
bilimit-compact then so is the (locally continuous) functor category
[J,C] .
o
Proof
(1) standard.
opep
(2) follows from the isomorphism C ~ CeP.

(3) trivial.

(4) Given a countable dir ected diagram D in [J, C], set (Vi , {( edi' Pdi) }dEll]))
to be the bilimit in C of Di and set Vi v f . Vj to be

V(Pdi;Ddf;edj ) (4.3)
dEll])

o
72 CALL-BY-PUSH- VALUE

4.3.2 Sub-Bilimit-Compact Categories


Recursively defined computation types are interpreted as isomorphisms
in Cpo" , which, as we have said, is bilimit-compact. But recursively de-
fined value types should be interpreted as isomorphisms in Cpo, which is
not bilimit-compact. What we can do is to find a supercategory (viz. the
category pCpo of cpos and partial continuous maps) which is bilimit-
compact, and whose isomorphisms are all guaranteed to be in Cpo. We
then say that Cpo is sub-bilimit-compact. However, we require some
additional conditions to ensure that sub-bilimit-compactness is closed
under - op, under arbitrary product and under [J, - J for every small cat-
egory J. In particular, in Sect . 6.10 we will need the fact that [W, CpoJ
is sub-bilimit-compact.
First some preliminaries.
Definition 4.3 1 A subcategory B of a category Cis lluf [Freyd, 1991J
when ob B = ob C.
2 A subcategory B of a Cpo-enriched category C is admissible when it
is closed under directed joins.
3 If B is a subcategory of TJ we write B .-t TJ for the category with the
objects of B and the morphisms of TJ , i.e. the unique category C such
that
B Clluf C Cfull TJ
4 A Cpo-enriched category B is sub-bilimit-compact within C when the
following conditions hold .
• C is bilimit-compact category containing B as a lluf admissible
subcategory.
• Suppose D and D' are countable directed diagrams in Cep, with
the same shape II]). Suppose (V, {(ed,Pd)}dEIIJ» is a bilimit of D
and (V', {(e~ ,p~)}dEIIJ» is a bilimit of D' . Suppose a is a diagram
morphism (i.e. natural transformation) from D to D' , and ad E
B(Dd, D'd) for each d. Then the join

V(Pd ;ad; e~) E B(V, V') (4.4)


dEIIJ>

(It is clear that Pd ; ad; e~ is monotone in d, so the join has to


exist. )
D

Proposition 31 If B is sub-bilimit-compact within C, then it contains


all the isomorphisms in C. D
Recursion and Infinitely Deep CBPV 73

Proof Let A f • B be an isomorphism in C. Let D and D' be the


singleton diagram A , and let a be the identity natural transformation.
Clearly (A , (idA, idA)) is a bilimit of D and (B , (J , f -l)) is a bilimit of
D'. For these bilimits , the join (4.4) is f. D

Proposition 32 1 The category Cpo is sub-bilimit-compact within


pCpo.
2 If C is bilimit-compact , then C is sub-bilimit-compact within itself.
3 If B is sub-bilimit-compact within C, then BOP is sub-bilimit-compact
within Cop.

4 If Bi is sub-bilimit-compac t within C, for all i E I , then D i E! B, is


sub- enriched compact within D i E! c;
5 Let J be a small Cpo-enriched category. (In particular , it could be a
small ordinary cate gory-i-j ust regard t he homsets as fiat cpos.) If B
is sub-bilimit-compact within C, then the (locally continuous) functor
category [J, B] is sub-bilimit-compact within [J, B] .-+ [J, C].
D

Proof

(1) That pCpo is bilimit-compact is well-known. To prove (4.4) , t ake


x E V. For sufficiently large d, Pd( X) must be defined , because of
(4.2). We know ad is total , and Cd is total like any embedding. So
ed(ad(Pd(x ))) is defined for sufficiently large d.
(5) To show that [J, B] ..-+ [J, C] is bilimit-compact , recall that the a
bilimit in [J, C] ar e given by (4.3) . It must therefore lie in [J, B],
bec ause B is sub-bilim it-compact in C.
The other parts are straightforward. D

4.3.3 Minimal Invariants


Now we recapitulate P itts' t heory, generalized in a straightforward
manner to bilimit-compact categories.
Definition 4.4 Let G be a locally cont inuous fun cto r (i.e. a fun ctor
which is cont inuous on homs ets) from CoP x C to C. Then an invaria nt
for G is a n obj ect D together with a n isomorphism i : G(D , D) ~ D . It
is a minimal in variant when the least pre-fixed point of the cont inuous
endofunction on C(D, D) taking e to i - 1 ; G(c, c); i is the identity. D
74 CALL-BY-PUSH- VALUE

Proposition 33 Suppose C is bilimit-compact. Let G be a locally con-


tinuous functor from Cop x C to C. Then G has a minimal invariant , and
it is unique up to unique isomorphism. D

Proof This is proved as in [Pitts, 1996]. D


Following [Pitts, 1996], we can show that any bilimit-compact cat-
egory is Cpo-enrichedly algebraically compact [Freyd, 1991]. But al-
gebraic compactness, although preserved by - op and by finite product,
does not appear to be preserved by countable product. This is why we
work with bilimit-cornpactness.
Minimal invariants are suitable for interpreting closed fixpoint types,
but when we have nested type recursion, we need a more general theory,
again taken from [Pitts, 1996].

Definition 4.5 Suppose C and B are Cpo-enriched categories and we


have a locally continuous functor
G : BOP x B x CoP X C -----+ C

Then a parametrized invariant for G is a locally continuous functor


F: BOP x B -----+C
together with an isomorphism

natural in D - and D +. It is a parametrized minimal invariant when,


for each D- and D +, the least pre-fixed point of the continuous endo-
function on

taking (e", e+) to

((i -D1 D ;G(D+,D - ,e+,e-);i D+ D-),(i -D1 D ;G(D-,D+,e-,e+);i D+ D-))


+, - , -, + '
D

We have seen that minimal invariants always exist, and the same is true
for parametrized minimal invariants.
Proposition 34 Suppose C is a bilimit-compact (or merely algebraically
compact) category, and B is any Cpo-enriched category. Then any lo-
cally continuous functor
G : BOP x B x CoP X C -----+ C
Recursion and Infinitely Deep CBPV 75

has a parametrized minimal invariant, unique up to unique isomorphism.


o
We will need to be abl e to relate minimal invariants computed in
different categories. We first recall the following result, sometimes called
"P lot kin' s axiom" .
Proposition 35 Suppose we have a commutative square of continuous
functions
f

h h

D - - - .... D
9
where C and D are pointed and h is strict. Let a be the least prefixed
point of f. Then f a is the least prefixed point of g. 0

The result we require is a categorical analogue to Prop. 35.


Proposition 36 Suppose we have a commuting square of locally con-
tinuous functors commuting up to natural isomorphism a

cOPxc~c

HOPxH 1 ~ 1 H

vO
PX Vc;--V
where C and V are bilimit-compact and H is locally strictly continuous.
Let (D , i) be a minimal invariant for F. Then (H D , (aD D; Hi)) is a
minimal invariant for G. 0

This is proved using Prop. 35. Prop. 36 can be generalized to parametrized


minimal invariants.

4.3.4 Interpreting Recursive Types


We know from the previous section that products of pCpo and Cpo !
are bilimit-compact categories, and we wish to use them to interpret
recursive types. To enable this, the cpo-operations that we have used
to interpret type construct ors must be extended to locally continuous
functors between these categories.
Proposition 37 • U extends to a locally continuous functor from
Cpo'' to pCpo, when we set (U g)(thunk a) to be thunk (ga). (Recall
76 CALL-BY-PUSH- VALUE

that the thunk can be ignored here; we write this only so that the
metalanguage conforms to CBPV.)
• L::iEI extends canonically to a locally continuous functor from pCpoI
to pCpo, when we set (L::iEI Ji)(i, a) to be (i, fza) if fza is defined,
and to be undefined otherwise.
• x extends to a locally continuous functor from pCpo x pCpo to
pCpo, when we set (f x f')(a, a') to be (fa, f'a') if fa and f'a' are
both defined, and to be undefined otherwise.
• F extends to a locally continuous functor from pCpo to Cpo", when
we set (Ff)(return a) to be return (fa) if fa is defined, and to be .L
otherwise, and we set (F f) .L to be L
• TIiEI extends to a locally continuous functor from (Cpo..l)I to Cpo" ,
when we set (TIiEIgdb to be Ai.(gi(i'b)).
• -+ extends to a locally continuous functor from pC poop x Cpo': to
Cpo", when we set (f -+ g)b to be

AX. { i((fX)'b) if f X is defined


otherwise.
D

Using Prop. 37 together with Prop. 30 we can interpret


• a value type A with m free value type identifiers and n free value
type identifiers by a locally continuous functor
(p'Cpo" x p'Cpo}?' x (Cpo..lop X Cpo")" - pCpo

• a computation type B with m free value type identifiers and n free


value type identifiers by a locally continuous functor
(p'Cpo" x p'Cpo)?' x (Cpo..lop X Cpo" )" _ Cpo':

In particular, a closed value type denotes a cpo and a closed computation


type denotes a cppo. We interpret ll,x.A and /lx.B as parametrized
minimal invariants. Where these types are closed , we have isomorphisms
[rtX.A] ~ [A[/lx.Alx]] in Cpo
[/lX.B] ~ [B[rtX.B IX]] in Cpo':

We thus obtain a semantics for CBPV with recursive types. It is obvi-


ously sound. To prove ad equacy, we use Pitts' methods [Pitts, 1996],
which work for any bilimit-compact category.
R ecursion and Infinitely Deep CBPV 77

4.4 Infinitely Deep Terms


4.4.1 Syntax
We now want to allow the bran ches of a term's parse tree to be infini te
branches, as in a Boh m tree. However , this is not always acceptable. To
see this, consider the following infinitely deep terms:
1

f-V thunk force thunk . . . : U11

f-C force thunk force thunk . . . : 11

f-V thunk force thunk force thunk . . . : Ul1

f-Cforce thunk force thunk force thunk . . . : l1


This is acce ptable. It is a di vergent com p utation and hen ce should deno t e ..L

f-V true: boo 1 Xo : bool , xi : bool f-c let true be X2• • • • : l1


f-V true : boo 1 Xo : bool f-c let true be xi . let true be X2· ••• : l1
f-Clet true be xo. let true be x i , let true be X 2 · •• • : l1
T h is is acceptab le. It is a divergen t com p utation and hen ce sho ul d denote . .1. .

f-Vtrue : boo 1 l-" fold (true , ... ) : J1X.(bool x X)

f-V true : bool f-V fold (true ,fold (true , . . .)) : j1X.(bool x X)

f-Vfold (t r ue, fold (true , fold (true , ... ))) : j1X .(bool x X)
T his is not acceptable. It sho u ld den ote an element of [j1X.(bool x X)]- but t his
is t he em pty cpo.

Eac h of these t rees has a single infinite branch. We need a conditi on


on branches t hat is sa tisfied by (1)-(2) but not by (3). The correct
requireme nt is as follows.
Definition 4 .6 An infinit ely deep parse-t ree for a te rm is acceptable
when it has no infinite branch tha t event ually (i.e. from some point
upward s) consists only of value- forming rules. 0

We st ress that a branch in an acceptable t ree is allowed to contain


infinitely many valu e-forming rules-this happens in (1).
78 CALL-BY-PUSH- VALUE

The branch condition in Def. 4.6 appears inelegant. A more abstract


characterization using induction and coinduction is given in Sect. 4.6.
For stack terms, we classify stack-forming rules together with value-
forming rules, so we do not allow to an infinite branch to eventually con-
sist of value-forming and stack-forming rules. The reason for this is not
apparent at this stage, but when we study control effects in Sect. 5.4.2,
we treat a stack as a special kind of value.

4.4.2 Partial Terms and Scott Semantics


Now that we have defined CBPV with infinitely deep terms, we want
to give describe Scott semantics for it, extending the Scott semantics for
finitely deep CBPV. To do this we add to the syntax an additional rule

r I- c ..1 : B
This larger set of terms that may use ..1 are called partial terms, whilst
terms that do not use ..1 are called total terms. The reader may wonder
what the difference is between ..1 and diverge, so we explain this as
follows. An infinitely deep term can be implemented as lazy tree, es-
sentially a program that repeatedly answers questions about its syntax.
For example, the computation Ax.d.i verge can be asked "what is your
outermost term-constructor?" and replies "Ax" . Next, it can be asked
"and what term-constructor follows that?" and it replies "diverge" .
By contrast, the computation Ax...1, when asked the second question,
diverges i.e. never replies. That is why a term without ..1 is called "total":
it always replies to queries about its syntax. The operational behaviour
of ..1 is to diverge, but this is not because there is a transition that
ensures this, as is the case for diverge. Rather, the CK-machine must
ask the current computation for its outermost term-constructor in order
to know which transition to apply. If the current computation is ..1, the
machine never receives a reply, so execution diverges.

Definition 4.7 We say that M <lfin N ( "Mis a finite approximant of N")


when M is finitely deep and N is obtained by replacing every occurrence
of ..1 in M by a computation. More abstractly, we can define <lfin to be
the least binary relation between terms such that <lfin is compatible (i.e,
closed under all term constructors) and ..1 <lfin N for all N. 0

For every finitely deep term M we define its interpretation [Mtin in the
usual way, setting [..1]p to be..1. Then, for every term M , we define
its interpretation [M]inf to be UM<lfinN[M]. It is clear that the set
{[M] : M <lfin N} is directed-the acceptability condition on branches
Recursion and Infinitely Deep CBPV 79
ensures its nonemptiness-so the join must exist. Furthermore, if M is
finitely deep then [M]inf = [Mt in, so [_]inf is an extension of [_tin.
Finally, we need to adapt the adequacy proof in Sect . 2.8 to include
infinitely deep terms. We define the various relations and prove their
admissibility just as we did there. We then prove that for any computa-
tion A o, ... ,An - 1 f-c M <lfin N : B, if ai ~A Wi for i = 0, ... ,n -1 then
-----7 •
[M]Xi a~ ~1J N[Wi!xi] ; and similarly for any values A o, . . . ,An - 1 f-v
f---7
U <lfin V : A. This is shown by mutual induction on M and U . By ad-
missibility, we see that [M] ~1J M for any closed computation M , and
this gives the desired result. ~

4.5 Infinitely Deep Types


4.5.1 Syntax
Having extended CBPV with infinitely deep terms, we proceed to
allow the parse-tree of a type to have infinite branches. Fortunately here
there is no need for restrictions on branches: any parse tree with finite
or infinite branches is acceptable.
For example, we have a value type

bool x (bool x (boo I x ... ))

This is the unwinding of j-lX.(bool x X) . There is no closed value of this


type because a putative term such as (true, (true, (true, ... ))) would
violate the branch restriction on terms.

4.5.2 Partial Types and Scott Semantics


Just as in Sect. 4.4 we extended the semantics for recursion to a
semantics for infinitely deep terms, so we can extend the cpo semantics
for type recursion to a semantics for infinitely deep types. We need to
introduce partial types, and we do this by adding a value type -.1 and a
computation type -.1. We define A <lfin B just as we did for types.
We first define [_tin, the semantics of finitely deep types. For this, we
interpret -.1 the same way as 0, viz. by the empty cpo, and we interpret
-.1 the same way as 1 (the nullary TI type), viz. by the l-element cppo.
Then we define [B]inf to be the bilimit of [At in over all A<lfinB, using the
fact that the set of finite approximants of B is directed and countable.
Soundness is trivial and adequacy is proved as for recursive types.
80 CALL-BY-PUSH- VALUE

We obtain isomorphisms such as


[A]inf ~ [Atin (A finitely deep)
[B]inf ~ [Bt in (B finitely deep)
[A X A,]inf ~ [A]inf X [A']inf
[U B]inf ~ U[B]inf

It would be desirable for these isomorphisms to be identities, but in the


cpo model they are not . If it were possible to make them into identities,
then it would also be possible to make the isomorphisms
[J-LX.A]inf ~ [A[J-LX.A/X]]inf
[J-LX .Btin ~ [B[fJ'x.B/x]]inf
into identities, and this is clearly not possible in the cpo model because
of the Axiom of Foundation. By contrast, in models such as information
systems [Scott, 1982], games [McCusker, 1996] and non-well-founded
cpos (replacing the Axiom of Foundation by the Anti-Foundation Axiom
[Aczel, 1988]) all these isomorphisms can be made into identities-we
omit details.

4.6 The Inductive/Coinductive Formulation of


Infinitely Deep Syntax
The branch condition on infinitely deep terms appears inelegant. In
this section (which the reader may omit as it is not used in the remainder
of the book) we give a more abstract characterization of infinitely deep
syntax. We write
• valtypes for the set of value types
• comptypes for the set of computation types
• contexts for the set of contexts
• valterms for the object in the category Setcontextsxvaltypes such that
valtermSr,A is the set of values r f-v V : A
• compterms for the object in the category Setcontextsxcomptypes such
that comptermsr,~ is the set of computations r f-c M : B .
We discuss only the case of countable tag sets, but an analogous discus-
sion applies to finite tag sets.
To see the issues, consider first the definition of (infinitely wide) CBPV
types:
A"= UBlLi EIAil11AxA
B ..= F A I DiE I u, I A ----7 B
R ecursion and Infinitely Deep CBPV 81

where I must be countable. This defines an endofunctor on Set x Set


given by:

(X, Y) f---7 (Y + LI countableXI + 1 + X 2 , X + LI countabley I + XY)


The reader may worry that t aking a sum over all countable sets is
problem atic. But ther e are two st raightforward solutions.
• We can take the sum over all countable sm all sets , relat ive to a
Grothendieck un iverse .
• Less drasti cally, we can take the sum over all initial segments of N.
This requires us to fix bijections that allow us to reg ard the set of such
segments as closed under finit e product and countable sum (indexed
over an initial segm ent of N).
Thus size is not a serious problem, and we will not address it further.
For finit ely deep syntax , the definition of typ es is inductive i.e. t he
pair (valtypes, comptypes) is t he carrier of an initi al algebra for this end-
ofunctor. When we allow infinitely deep typ es, the definition of types
becomes coinductive i.e. (valtypes, comptypes) is the carrier of a te rmina l
coalgebra for this endofunctor.
The definition of CBPV terms given in Fi g. 2.1 similarly describes an
endofunctor'' on Setcontexts xvaltypes x Setcontexts xcomptypes . It must be of
t he form (F, G) where
• F : Setcontexts xvaltypes x Setcontextsxcomptypes ---+ Setcontexts xvaltypes
• G : Setcontexts xvaltypes x Setcontexts xcomptypes ---+ Setcontexts xcomptypes

but we will not wr ite F and G explicit ly.


We see that (valterms, compterms) is the carrier of an initial algebra
for this endofunctor. But when we allow infinite ly deep terms, it is not
the case that (valterms,compterms) is the carrier of a terminal coalge-
bra for t his endofunctor, because of the branch condit ion. However ,
(valterms, compterms) is certainly a fixpoint of t he endofunct or in the
sense t ha t
valterms C:>! F(valterms, compterms)
compterms C:>! G(valterms, compterms)

How can we characterize this fixpoint ? Clearly we require some kind


of mixed inductive/coinductive definition: values are inductively defined ,

2We gloss over issu es of ide nt ifier binding. See [Alt en kirch and Re us, 1999; F iore et al., 1999]
for a fuller discussion .
82 CAL L-BY-PUSH- VALUE

computations are coinductively defined. But the coinductive part must


be (loosely sp eaking) on the outside, because otherwise we will exclude
infinite branches that contain infinitely many value-forming rules, and
we have already seen that this is too restrictive.
To express this, we write p,X for initial algebra and vX for terminal
coalgebra.
Proposition 38 We have t he following description of infinitely deep
terms:
compterms c:>!. vY.G(p,X.F(X , Y) , Y)
valterms c:>!. p,X.F(X , compterms)
o
This is proved by giving an explicit representation of the funct ion
Y t-+ p,XF(X, Y)
We omit details.

4.7 Relationship Between Recursion and


Infinitely Deep Syntax
We said in Sect. 4.1 that recursion and infinitely deep syntax are, in
a sense, equivalent. We now explain this sense, in a very informal way,
using examples.
Any recursion can be unwound infinitely often. For example, if we t ake
t he recursive type /J,X.(l+X) , this can be unwound to give l+/J,X.(l+X) ,
t hen unwound again to give l+(l+p,x.(l+X)) , and so forth. Ultimately,
we obtain the infinitely deep type 1 + (1 + (1 + . . . )) . Thus if we have a
semantics for infinitely deep syntax , it provides a semant ics for recursion
too.
On the other hand, if we have an infinitely deep term or typ e, it can
be expressed using a countabl e collect ion of simultaneo usly recursive
definitions . For example, t ake the infinitely deep type A = 0 + (1 + (2 +
(.. . ))) . We name t he sube xpressions of this as follows:
Ao 0 + (1 + (2 + ))
Al 1 + (2 + (3 + ))
A2 2+(3+(4+ · · ·))
Now we can define these types by mutual recursion:
Ao 0 + Al
Al 1 + A2
A2 2 + A3
Recursion and Infinitely Deep CBPV 83

T hus any semantics for recur sion t hat can interpret countable simulta-
neous recursions gives us a semant ics for infinitely deep syntax.
Sometimes it is easier to work wit h recursion , sometimes wit h in-
finitely deep syntax. One advantage of the form er is t hat , by allowing
only finitely deep syntax, we have a clear notion of compositional se-
mantics . Finitely deep syntax is an initi al algeb ra for an endofunctor,
and a compos it ional semantics is one spec ified by another algebra for
t his endofunctor- t he interpreta tion is t hen given by t he unique algebra
homomorp hism from the syntax to t his algeb ra [Goguen et al., 1979]. By
contrast, it is not clear in wha t sense t he semantics for infinitely deep
CB PV t hat we have cons idered can be said to be composit iona l.

4.8 Predomain Semantics For CBPV


4.8.1 Domains and Predomains
So far , we have seen how to interpret CBP V in cpos and cppos. Bu t
freq uently one wishes to restrict attention to a special class of w-a lgebraic
(or at least w-cont inuous) cpos called "predomains" . A predomain with
a least element is called a "domain" .
T here are vari ous class es of predomai n one could work wit h , but t hey
share the following properties.
• They all include t he flat cpo N.
• They all exclude the uncountable flat cpo N -t N, because it is not
w-continuous.
• Consequently, t hey are not cartesian closed categories.
Some languages considered in t he literature (e.g. t he monadic met a-
language of [Benton and Wad ler , 1996]) allow a -t operation on valu e
types. T his has two disadvantages, as far as cpos are concerned .
• It rules out a pred omain semant ics, becau se t he ty pe nat -t nat
cannot be int erpreted in predomains.
• It rules ou t general type recursion , if a cpo semantics is desired ,
because t here is no cpo A such t ha t A ~ A -t 2.
We have seen t hat CBPV, by contrast, allows general type recursion,
and we shall soon see t hat it has a predomain semantics.

Definition 4.8 1 A cppo A is a (Scott-Ershov) doma in when it is


w-a lgeb raic and cons istently complete i.e. every consistent (upper-
bo unded) finite subset has a joi n. We wri te DomStr for t he full
subcategory of Cpo': on domains.
84 CALL-BY-PUSH- VALUE

2 A cpo A is a (Scott-ErshovjAb ramsky-McCusker) predomain when


it is a countable disjoint union of domains. (T his implies A is w-
algebraic.) We write Predom for the full subcategory of Cpo on
predomains.
o
It is clear t hat a domain is precisely a pointed predomain.
When working with a predomain , one generally wants to consider the
pos et of compact eleme nts, as explained in [Plotkin, 1983; Stoltenb erg-
Hansen et al., 1994].

Definition 4 .9 1 A countable conditional upper semi lattice or w- cusl


is a consiste nt ly complete, countable poset (A , ~) with a least element
..1.

2 A pos et is an w-multi cusl 3 when it is a countable disjoint union of


w-cusls .
o
We have the following constructions, inverse up to poset isomorphism .

ideals
w-cusls domains
compact els.

f
w-multicusls
ideals r
predomains

compact els.

4.8.2 Interpreting Type Recursion In Predomains


and Domains
We would like to show that Predom is sub-bilimit-compact within
some appropriate supercategory. The definiti on of t his superc ategory,
like our definition of predomain, is bas ed on [Ab ramsky and McCusker,
1998].

Definition 4.10 A partial-on-minim als fun ction from predomain A to


predo main B is a partial conti nuous fun cti on su ch t hat f is defined on
x iff f is defined on the least element below x. We write Partmin for
the categ ory of predomain s and partial-on-minimals fun ctions. 0

3T he term "pre- cusl' has already been used .


Recursion and Infinitely Deep CEPV 85

Following [Stoltenberg-Hansen et al., 1994], we can characterize in a


simple way t he (e,p)-pairs in Partmin and in DomStr.
Proposition 39 1 Let A and B be t he w-multicusls of compact ele-
ments of predomains X an d Y respectively. Let i be the an injection
i from A to B that preserves and reflects :::;; , minimality, inconsistency
an d jo ins. T hen i determines an (e,p)-pair in Partmin from X to
Y, where

ex V i(u)
a EA,a ~ x

py VaEA,i(a) ~y U if {u E Ali(u) :::;; y} is non-empty


{ und efined ot herwise

so e(py ) = {V aEA,i(a) ~y i (u) if { u E Ali( u) :::;; y} is non-empty


und efined ot herwise

Furthermore , every (e, p) pair in Partmin is obtained in t his way,


setting i to be t he restriction of e to compact elements.
2 Let A and B be the w-cus ls of com pact elements of domains X and
Y . An injecti on i from A to B t hat preserves and reflects :::;; , ..l ,
inconsistency and joins determines an (e,p)-pair in DomStr from X
to Y , by t he same formulas as in (1). Furthermore, every (e,p) pair
in DomStr is obtained in this way, setting i to be the restriction of
e to compact elements.
o
Proposition 40 1 DomStr is bilimit-compact.
2 Predom is sub -b ilimit-compact in Partmin.
o
Proof (2) Given a countable directed diagram D of (e,p)-pairs, we
use Prop. 39(1) to obtain a diagram of w-multicusls Ad and injec tio ns
Ad idd , . A d' an d construct t he colimit of t his as an w-mult icusl C
wit h injections Ad id • C . (C is constructed as a quot ient of the
disjoint union of t he posets {Ad}dElIJ> , j ust like colimits in Set. ) We let
V be the predomain corresponding to C. To prove (4.2), it is sufficient
to prove it for compact elements of V . If c is such a compact element
(i.e. c E C) , then, by t he construction of C , c is in t he range of i« for
sufficiently large d. For such d, the explicit description in Prop. 39(1)
shows that Pd; ed takes u to a . Hence VdElIJ>(Pd ; ed) takes a to a, (1) is
proved sim ilarly. 0
86 CALL-BY-PUSH- VALUE

Of course, Prop. 40 can also be proved directly, as done in [Smyth


and Plotkin, 1982]' but working with compact element s makes the con-
struction of the bilimit more intelligible.
We want to interpret infinitely deep CBPV in predomains and do-
mains, making sure that this agrees with the interpretation in cpos and
cppos. We first note that the embe dding of DomStr in Cpo': and
the emb edding of Partmin in pCpo ar e locally strictly continuous. So
Prop. 36 is applicable.
We then must show that all the functors described in Prop. 37 do
indeed restrict from pCpo and Cpo': to Partmin and DomStr. This
is straightforward.
Chapter 5

SIMPLE MODELS OF CBPV

T his chapter does not dep end on Chap. 3 or Chap . 4. However , all
the models in this chapter validate the equations of Ch ap . 3, and can
interpret complex values.

5.1 Introduction
The goal of Part II is to advance the following claim.
Whenever we ar e studying effect ful higher-order langu ages (a nd re me mbe r
t hat mere div ergen ce makes a lan guage "effect ful" ), t he semantic primiti ves
are given by CBPV. It is t her efore a goo d choice for our lan gu age of st udy.

While this is cer tainly a rad ical claim, we assemble, t hroughout Part II ,
extensive evidence for it. In a wide range of fields , we see firstly that
CBPV semantics is simpler than the tradit ional CBV and CBN seman-
tics , and secondly that these traditional semantics can be recovered from
the CBPV semantics-so we do not lose out by shifting our focus to
CBPV.
Admittedly, we encounter excep tions, where a CBV model does not
decompose naturally into CBPV. These except ions ar e

• the model for errat ic choice with t he constraint that choice must be
finit e (Sect . 5.5.3)

• the poss ible worlds mod el for cell generation with the const raint of
"paramet ricity in ini tializations" (Sect . 6.9)

• the model for input based on Moggi's input monad [Moggi, 1991].

The first two ar e constrained variants of a simpler CBV mod el that does
decompose into a CBPV mod el, so we do not consider t hem to be a

89
P B Levy, Call-By-Push-Value
© Springer Science+Business Media Dordrecht 2003
90 CALL-BY-PUSH- VALUE

major objection to our claim. A more optimistic position regarding the


finite choice and input effects is argued in Sect. 12.2.
We have already seen the decomposition into CBPV for printing and
divergence, as well as for operational semantics, in Chap. 2. In this
chapter we look at global store, control effects, erratic choice and errors,
and at various combinations of these effects. This range of "simple
models" is based on [Moggi, 1991], although we do not treat Moggi's
example of "interactive input" .
We first look at semantics of values, in Sect. 5.2, as this is common
to all the models in the chapter. Then we devote one section to each
effect; these sections can be read independently of each other.
As the semantics of values is straightforward, the difficulty lies in the
semantics of computations. To invent it, there are two useful heuristics
that can be applied. One is to take a known CBV (or CBN) model and
look for a decomposition.

• For example, consider the traditional global store interpretation of


A -+CBV B viz. 3 -+ ([A] -+ (3 x [B])). We immediately see
the decomposition into U(A -+ F B); it appears that U will denote
3 -+ -, that -+ will denote -+, and that F will denote S»: -. Thus the
CBPV type constructors have simpler interpretations than -+CBV.

• As another example, consider the traditional continuation semantics


for A -+CBV B viz. ([A] x ([B] -+ Ans)) -+ Ans. We immediately
see the decomposition into U(A -+ F B); it appears that U and F
will both denote - -+ Ans, and -+ will denote x. Again the CBPV
type constructors have simpler interpretations than -+CBV.

• For both of these examples, there are corresponding CBN semantics


presented in the literature: A -+CBN B is interpreted in [O'Hearn,
1993] as (3 -+ [A]) -+ [B] (for global store) and in [Streicher and
Reus , 1998] as ([A] -+ Ans) x [B]. Each of these makes apparent
the decomposition of A -+CBN B into (U A) -+ B. Again, the se-
mantics of the CBPV type constructors are simpler. In fact the CBN
semantics looks quite strange; CBPV thus provides a rational recon-
struction for it.

The other heuristic, which we shall use in this chapter, is to guess in


advance the form of the soundness theorem and proceed from there.

5.2 Semantics of Values


We describe the semantics of values at the outset, because it is straight-
forward and it is the same across the different models in the chapter
Simple Models Of CBPV 91

(except for t he new model of Sect. 5.5.4). We will consider models using
sets and models using cpos. In all of the set mod els,
• a value type denotes a set
• in par ti cul ar , L iEIAi denotes the set L iEI[A i] and A x A' denotes
t he set [A] x [A']
• a context A o, . . . , A n- I denotes t he set [A o] x . . . x [A n-d
• a value r f-v V : A denotes a fun ction from [r] to [A] .

Simil arly, in the cp o mod els,


• a value type denot es a cpo;
• in particular, L iE/Ai denot es the cpo L iEI[A i] and A x A' denotes
the cpo [A] x [A'] ;
• a conte xt A o, . . . , An-I denotes the cpo [A o] x ... x [A n-I] ;
• a value r f-v V : A denotes a cont inuous fun ction from [r] to [A].

5.3 Global Store


5.3.1 The Language
We take the simplest possible case of global store: we suppose there
is just one cell cell t hat stores an element of the countable set S . If we
want the syntax to be finit ar y, we restrict to the case that S is finit e.
We t hus add to the basic CBPV language const ructs for assignment
and reading:
r f-c M : B ... r f- M s : A . .. sES
- (s E S)
r f-c cell := s, M : B r f-c read-ceIl-as {. . . , s.Ms , . . . }

(We cont inue our pract ice of treating commands as prefixes.)


For big-st ep semantics, we define a relation of the form s, M ..u- s', T ,
where s, s' E S . We oft en write s as cell f-7 V , meaning "cell cont ains
the value V " . To define ..u-, we replace each rule in Fig. 2.2 of t he form
(2.1) by

and add the rules


s' , Mil"'J' s" , T s ' , MS' ..u- s",T
s, (cell := s'. M)..u- s" , T s', read-ceIl-as {.. . .e .i«; . .. } ..u- s", T
92 CA LL-B Y-P USH- VA LUE

Proposition 41 For every s E 5 and closed computation M , t here


exists unique s' , T such t hat s , M .lJ. s' , T . 0

This is proved similarly to Prop. 10. We can also adapt t he CK-machine


to this computat ional effect , bu t we omit t his.
We adapt the definition of observational equivalence.
Definition 5.1 Given two computations r I- c M , N : B , we say M ':::: N
when for any ground context C[.] and any s E 5 , we have
s, C[M ].lJ. s', r et ur n n iff s ,C[N].lJ. s' , r et ur n n
Similarly for two valu es r I- v V, W : A. o

5.3.2 Denotational Semantics


Computations
We seek a denotational semantics for the language of Sect. 5.3.1. Since
t here is no divergence, we use a set model. The sema nti cs of values is
given in Sect. 5.2- the difficulty lies in the int erpretation of computa-
tions.
While logically we should present the sem an tics first , and then state
t he soundness theorem , t his makes t he interpreta tion of typ e construc -
tors appear unintuitive. So we will pro ceed in reverse order. We will
state first the soundness t heorem t hat we are aiming to achieve, even
t hough it is not yet mean ingful , and use t his to motiv ate t he semantics.
We expec t t he soundness result to look like t his:
Proposition 42 (soundness) Let M be a closed computation. If s , M .lJ.
s' , T then [M] s = [T] s'. 0

In Prop. 42, the denotation of M takes a store as an argument. More


generally, we would expect a comput at ion r I- c M : B to take both store
s E 5 and environment p E [r] as arguments. Thus M should denote a
fun ction from 5 X [I'] to some set -we call this set [B]. Intuitively, [B]
is the set of behaviours for a computation of type B , in a given store
and environment .
We can use this idea t hat a computati on typ e denot es a set of be-
haviours to motivate the interpret ation of the typ e constructors.
• The beh aviour of a computation of typ e F A is to terminate in a state
s E 5 returning a valu e V of typ e A. So F A denot es 5 x [A ].
• The behaviour of a computation of ty pe TI iEIBi is to pop i E I , and,
dep ending on t he i popped , to behave as a computation of ty pe B i .
So TI iE1B i denotes TI iEI[B i ].
Simple Models Of CBPV 93

• The behaviour of a computation of type A -+ B is to pop a value of


type A, and, depending on the value popped, to behave as a compu-
tation of type B . So A -+ B denotes [A] -+ [B]'
• A value of type U B can be forced in any store s E 8 , and depending
on this store, will behave as a computation of type B. So U B denotes
8 -+ [B].
Notice in particular that a returner r f-C M : FA denotes a function
from 8 x [r] to 8 x [A]. Notice too the semantics of CBV functions:

[A -+CBV B] = [U(A -+ F B)] = 8 -+ ([A] -+ (8 x [B]))


As we said in Sect . 5.1, this is the traditional CBV semantics for global
store.
The semantics of terms is straightforward. Here are some example
clauses:

[return V](s, p) (s, [V]p)


[M to x. N](s , p) [N](s' , (p, x 1-7 a))
where [M]( s,p) = (s' ,a)
[thunk M]p As.([M] (s, p))
[force V]( s, p) s'([V]p)
[Ax.M](s, p) Ax.([M](s , (p,x 1-7 x )))
[cell := s'. M]( s, p) [M](s' , p)
[read-cell-as {... , s.Ms , ... }](s' ,p) [MS'](S' , p)
It is easy to prove Prop. 42.
Corollary 43 (by Prop. 41) If M is a ground returner , then s, M JJ-
s' ,return n iff [M]s = (s' ,n) . Hence terms with the same denotation
ar e observationally equivalent. D

Stacks
As we stated in Sect. 2.6.2, for each of our models we can also give
semantics of stacks. In the case of global store, we can see that a stack
fiB f-k K : C, in a given environment p E [r], transforms a behaviour
of a computation M of type B into a behaviour of a computation of type
C. This transformation is not dependent on the initial store, although
M may set the store (say if B = FA) and the transformation will then
depend on this new store.
Thus K will denote a function from [r] x [B] to [C]. We omit the
interpretation of stack terms, which is straightforward.
94 CALL-BY-PUSH- VALUE

5.3 .3 Combining Global Store With Other Effects


The mod el for global store in Sect . 5.3.2 generalizes. If we have any
CBPV model, we can obtain from it a model for global store.
As an exa mple, consider the printing model for CBPV. We seek a
model for global sto re toge t her with print. T he big-st ep semantics will
have the form s , M .lJ. m , s', T -we omit the det ails, which are st ra ight -
forward.
The denotational sema nt ics for globa l store with print is organiz ed
as follows:
• a value type (and hence a cont ext) denotes a set
• a computat ion typ e denot es an A-set
• a value r f-v V : A denotes a funct ion from [r] to [A]
• a computation I' f-c M : B denot es a fun ction from S x [r] to t he
carrier of [B]
• a stack rjB f-k K : 0 denot es a homomorphism over [r] from [B] t o
[0].
We use CBPV as a met alanguage describing the printing model, as
explained in Sect. 2.8. For exa mple,we write FA for t he free A-set on
the set A , and we write UB for the carrier of the A-s et B . Wi th this
notation , the semantics of types is given by
[FA] F(S x [A])
[TIiE1Bi] TIiEI[B i]
[A ---+ B] [A] ---+ [B]
Semantics of terms : some example claus es
[return V](s ,p) return (s, [V]p)
[M to x. N](s, p) [M]( s , p) to (s' , a).
[N]( s', (p, x 1-+ a))
[thunk M]p thunk As.([M](s , p))
[force V]( s, p) s'force ([V]p)
[Ax.M](s , p) Ax .([M](s , (p, x 1-+ x )))
[[.J to x. N :: K]p [.J to (s,x ).
[N](p, x 1-+ x) :: [K]p
[cell := s' . M ](s, p) [M]( s', p)
[read-ceIl-as { ... ,s.Ms, .. .}](s' ,p) [Md( s' ,p)
[print c. M]( s ,p) c * ([M]( s , p))
Si mp le Models Of CBPV 95

Proposition 44 (soundness) If s, M JJ. m, s' , T t hen [M ]s m *


([T]s) . 0

Corollary 45 (by the analogue of Prop. 41) If M is a ground return er ,


t hen s , M JJ. m , s' , return n iff [M]s = (m, s' , n) . Hence terms wit h t he
same denotati on are observationally equivalent . 0

In a similar way, we can obtain a mo del for global store wit h rec urs ion .
T he semantics of ty pes and terms are as above except t hat we now
un derstand t he metali ngui sti c U,F etc . as referri ng to the Scott model
rather t han t he printi ng mo del.

5.4 Control Effects


5.4.1 letstk and changestk
For our explanat ion of control effects, we will use t he CK-mac hine for
non-closed computations as in F ig. 2.4. Big-step semantics is unsui t abl e
for a language with control effects .
We add to CBPV 1 two commands letstk x an d changestk K .
• letstk x means "let x be t he current stack" .

• changestk K means "change t he current stack to K " .

Thus we have two additional machine transitions

letstk x. M K
~ M[K/ x] K

changestk K . M L
~ M K
We illust rate t hese constructs with an example program:
let thunk (
AX.
changestk x .
Xz.

IThe CBV cont ro l op erators (as in ML) are translated into CBP V as follow s:
cont A as stk FA
letc c x . M as letstk x . M
throw M N as M t o x. N to y. ( c hang e s t k x. ret urn y)

We have to use the t erminology "c urre nt st ac k" rather th an "cu rre nt cont inuation" (t he
phras e us ed in CBV) becau se in C BP V not every stack is a co nti nuation.
96 CALL-BY-PUSH- VALUE

return 3 + z
). be y
( 7'
print "he l l o" .
letstk a.
( ( A u.
true'
a'
force y
) to v in
return v+2
)
) to w.
return w + 5
• By t he time we reach t he line letstk a , we have printed hello and
the current stack consists of an ope rand 7 together wit h the to w
continuation (i.e. the continuation tha t begins on the line to w in),
so a is bo und to this stack.
• By the time we force y the current stack consists of operands a and
true and the to v cont inuation.
• When we force y, we pop the top operand, which is a , and bind x to
it. We now change the current stack to a.
• We pop the top operand, which is 7 (again) and bind z to it .
• We return 10 to t he current continuation which is t he to w continu-
ation. Hence we return 15.
Notice how t he stack discipline has been completely lost ; in t he absence
of t he control effects we would expect force y to return a value to t he
to v continuation , but we have used changestk to override t his.

5.4.2 Typing Control Effects


T he way t hat we type control effects follows [Duba et al., 1991]-
we merely adapt it from CBV to CBPV. The idea is that whereas, in
Chap. 2, a stack inhabi ted a special judgement f-k, it will now be re-
garded as a "first-class citizen", i.e. a value . Since it is a value , it must
have a value type. So for every computation type B , we int roduce a
value type stk B . A value of this type is stack from B.
Thus the two classes of types are now given by
A· ·= UB I l:iE!Ai I 1 I A x A I stk B
B ··= FA I D i E! B i I A -+ B
Simple Models Of CBPV 97

and we add the rules for letstk and changestk in Fig. 5.1. Notice

r , x : stk II f-c M : 11 r f-v K : stk II r f-c M : II


r f-c letstk x. M : B r f-c changestk K . M : B'

Figure 5.1. Typing Rules for Con t rol Op erato rs

that changestk K. M can be given any type, like diverge. It is a


nonreturning com mand in the sense of Sect . 2.9.2.
The language that we have presented so far is called CBPV + control.
Notice that our t ransition rule for letstk t akes us outside this lan guage,
bec aus e it substitutes a st ack K for an identifier x. Thus, if we wish to
typecheck configurations, we are going to need a way of incorporating
stacks into computations and values. This is what we do in the next
section.
The various forms of CBPV+ control are shown in Fig. 5.2, which
extends Fi g. 3.1. We defer the equat iona l theory, and the proof that the
exte nsion is computat ion-unaffect ing, until Sect . 7.8.3.

programs CK-machine equational theory

CBPV -------~,.~ CBP V

!
+ complex valu es
conservative

CBP V ~ CBPV
+ stacks + stacks
... j +comrux v~u~/,tack'
CBP V - - CI3PV ~ CBP V
+ control + cont rol + cont ro l
+ stacks + stacks
+ complex values (in c!. ·i gn or e d )

Figure 5.2. Vari eti es of CBP V with control


98 CA LL-B Y-PUSH- VALUE

5.4.3 Regarding nil As A Free Identifier


Let us consider t he following trace.
(4 ' >.y. r e t ur n y) to x .
return true F b ool nil F b ool
"""' 4' >.y .r e t u r n y F n at [.J to x. return true :: nil F b ool
"""' >.y.return y nat ~ F n at 4 :: [.J to x . return true :: nil Fbool
"""' return 4 F nat [.J to x. return true :: nil F b ool
"""' return true F b ool nil F b ool

We said in Sect . 5.4.2 t hat a stack from B should be a value of ty pe


stk B . For example, t he stack
I nat ~ F n at f-k 4 :: [.J to x . return true :: nil : F b ool (5 .1)

in the above example should be a value of ty pe stk (nat -+ Fnat ).


Now this stack contains nil whi ch is a stack from Fbool, and we can
subst it ute for nil any stack from Fbool (that is conca te na t ion). So it
makes sense to think of nil as an identifier of ty pe stk Fbool. Thus,
when we regard (5.1) as a value, it makes sense to typecheck it as follows.
nil: stk F b ool f-v 4 :: [.J to x . return true :: nil : stk (n a t ~ F n a t)

More generally, in CBPV + control + st acks, we do not require t he f-k


j udgement , becau se instead of writ ing r iB f-k K : C we can write
r ,nil : stk Q f-V K : stk !1

Not ice t he swapping of B and C aroun d t he f-. It will lead us to an


important duali ty in Sect . 5.7.
A configuration of t he CK-machine will have t he for m

r M B K

where r f-c M : Band r f-VK : stk B. We call t his a configuration in


context r . There is no need for a ty pe C on the right, because nil: stk C
will be included in r. Recall from Sect . 1.4.2 t hat, given a term P in
context r , we wri te nil P to indicate the weakened term in conte xt I' , nil.
Looking at Fi g. 5.3, we can immediately write down t he typing rules
for st acks, presented in Fig. 5.4. We have added the symbol . to
t he stack-forming constructs, which can probably by ignored by all but
t he most pedanti c read ers. T he difference between :: and -t: is t hat ..
contains an implicit weakeni ng by nil. This is spelt out in Fig. 5.5.
All the resul ts of Sect . 2.3.4 adapt . In parti cul ar we have
Proposition 46 (determinism) (d. Prop. 11) For every configura-
tion M , K in context r , precisely one of t he following hold s.
1 M , K is not te rminal, and M , K """' N , L for a unique configuration
N , L in context r.
Simple Models Of CBPV 99

Initial Configuration To Evaluate r f-c M : Q

r ,nil : stk Q nilM nil

Transitions

r letstk x. M 11 K
r M[K/x] II K

r changestk K . M l1' L
r M 11 K

r let V be x. M II K
r M[V/x] 11 K

r M to x. N 11 K
r M FA [.J to x. N ·:: K

r return V FA [.J to x. N ·:: K


r N [V /x ] 11 K

r fo rce thunk M II K
r M II K

r pm (i, V ) as { . . . , (i ,x) .M i , ... } II K


r M ;[V / x] II K

r pm (V, V' ) as (x, y) .M II K


r M[V/x , V ' /y] 11 K

r i'M -B., K
r M ITiEIlli i·:: K

r -X{ ... . i .M«, ... } IT iEI l1 i i ·:: K


r M; -B., K

r V 'M 11 K
r M A -+l1 V ·::K

r -Xx .M A -+l1 V ·::K


r M [V/ x] II K

T erminal Configurations

r , z : stk FA , r' return V FA z


r , z : stk IT iEI l1 i , r ' -X{ . .. .i.M«, . .. } ITiEIlli z
r , z : stk (A -+ 11), r' -Xx.M A -+ l1 z
r, z : Ull,r' force z 11 K
r, z : L iEI A i , r ' pmz as { . . . . i .Mi , .. .} 11 K
r , z : A X A' , r ' pm z as (x , y) .M 11 K

Figu re 5.3. CK-Machi ne With Cont rol


100 CALL-BY-PUSH- VALUE

r , x: A f-c M : Ii r f-v K : stk B


r f-v [.] to x. M -i: K : stk FA

r f-v K : stk Iii r f-v V : A r f-v K : stk Ii


r f-v i ·:: K : stk TIiEIBi r f-v V·: : K : stk (A -+ B)

Figure 5.4. Typing St acks in CBPV + Con t rol

CBPV CBPV + control


stack fiB f-k K : C r,nil : stk C f-v K : stk B
configuration r , M , B , K , C (r,nil : stk C) , nilM,B,K
[.] to x. N :: K [.] to x. mIN -i: K
i :: K i·: : K
V ::K nilv -i: K

Figure 5.5. Translating CK-rnachine for CBPV into CK-rnachine for CBPV+con trol

2 M, K is terminal, and there do es not exist N , L such that M, K ~


N ,L.

Proposition 47 (cf. Prop. 12) For every r configuration M , K there


is a unique terminal r-configuration N , L such that M , K ~ * N, L , and
there is no infinite sequence of transitions from M, K. 0

We defer the proof of this to Sect. 7.5.3.

5.4.4 Observational Equivalence


In the presence of control effects, we replace Def. 2.7(2) by

Definition 5.2 Given two computations r f-c M , N : B , we say M ~ N


when for any (closed) ground context C[.] we have

nilC[M],nil ~* return n ,nil iffnilC[N],nil ~ * return n ,nil

Similarly for values r f-V V, W : A. o


Since elM] and C[N] are required to b e closed (by the definition of
ground contex t ), they cannot contain nil.
Simple Models Of CBPV 101

5.4.5 Denotational Semantics


Computations
We seek a den otational semantics for the language described in Sect. 5.4.1.
This kind of model is t raditio nally called continuati on semanti cs. We
will continue to use this nam e, even though "st ack-passing" would be
more appropriate in t he CBPV setting.
Since there is no divergence, we work with sets rather than cpos.
The semantics of values is given in Sect. 5.2-the difficulty lies in the
int erpretation of computations. As in Sect. 5.3.2 , we will state first the
soundness theorem that we are aiming to achieve, even though it is not
yet meaningful, and use this to motivate the semantics.
Proposition 48 (soundness) Suppose that M , K """ N, L where
r f-c M: B r f-v K: stk B
r f-c N: B' r f-v L : stk B'
Then , for any environment p E [r] ,
[M](p, [K]p) = [N](p, [L ]p) (5.2)
o
Notice t he similarit y between this statement and Prop. 42. There, a
computation M can change t he st ore, so [M ] takes st ore as an ar gument.
Here, a computat ion M can change its stack, so [M ] takes a stack as an
argument .
In Prop. 48, we know that [K]p E [stk B]. So [M ] mu st be a function
from [r] x [stk B] to some set ; similarly, [N] mu st be a function from
[r] x [stk C] to the same set . This set , whi ch we call Ans (the "set
of an swers") cannot dep end on the type of M , becaus e M and N have
different types. It is an arbit rary set which remains fixed throughout
the denotational semantics.
We proceed to the semantics of types, which is given in Fig. 5.6(1).
At first sight, these equations looks strange, but they make sense once
we know that whenever we see [B] , for a computation type B , we should
mentally replace it with [stk B]. To put it anot her way, the semantic
brackets [-] for computation typ es contain a "hidden" stk. To explain
the semantics of typ es, we first look at some equat ions which do not re-
quire any mental replacement (because they do not mention deno tations
of computation ty pes) and so make sense immedi ately.
• [s t k (A --+ B)] = [A] x [s t k B ] follows from t he fact that a stack
from A --+ B consists of a value of ty pe A together with a stack from
B.
102 CALL-BY-PUSH- VALUE

1 Official presentation-compositional
Values types Computation types
[Um W] -+ Ans [F A] [A] -+ Ans
[l::i EIAd l::i EI[Ad m iEI~i]
[A x A'] [A] X [A'] [A -+m =
l::iEIWJ
[A] x W]
[stk~] un
2 Intuitive presentation-not compositional
Value types
[Um [stk m-+ Ans [stk FA] [A] -+ Ans
[l::iE1Ad l::iEI[Ad [stk rlEl~i] l::i EI[stk ~i]
[A x A'] [A] x [A'] [stk (A -+ B)] [A] x [stk B]
Computation types
W] [stk Q]

Fiqure 5.6. Semantics of types-two equivalent presentations

• [TIiEIBi] = L:iEI[B i] follows from the fact that stack from TIiEIBi
consists of a tag i E I together with a stack from B i .

• [stk FA] = [A] ---+ Ans is plausible, because an A-accepting contin-


uation, when it receives an A-value, executes leading to an answer.

• [UB] = [stk B] ---+ Ans because a value of type U B is a thunk that


can be forced against any stack from B, and then executes leading
to an answer.

Now these equations, together with the standard equations of L: and


x, completely determine the semantics of value types. In other words,
there is a unique function [-] from value types to sets that satisfies them.
But this function is not given compositionally. Therefore, in Fig. 5.6, we
write [B] as shorthand for [stk B], for the sole reason that this enables
us to rearrange these equations into a compositional semantics.
We can now say that a computation r f-c M : B denotes a function
from [r] x [B] to Ans. Here are some example clauses for semantics of
Simple Models Of CBPV 103
te rms :

[r e t ur n V](p , k) ([V] p)'k


[M to x. N](p, k) [M]( p, >.a.([N ]( (p, x I-? a), k)))
[thunk M]p >'k.([ M](p, k))
[f or ce V](p , k) k'([V] p)
[>'x.M]( p, (a, k)) [M]((p, x I-? a), k)
[V 'M](p, k) [M]( p, ([V] p, k))
[l et s t k x. M](p, k) [M]((p, x I-? k) , k)
[changestk K. M ] (p, k) [M](p, [K] p)
[[.J to x. N .:: K] p >.a.([N]((p, x I-? a), [K]p))
[V ·: : K]p ([V]p , [K]p)

These semant ic equations are of course ver y similar to t he machine t ra n-


sit ions .
We can now prove P rop. 48 straightforwardly.

Corollary 49 (by Prop . 47) Suppose Ans has 2 elements a =1= b. For a
set N and eleme nt n E N , wri t e I N,n for t he fu nct ion from N to Ans t hat
takes n to a and everything else to b. T he n for any closed gro und returner
M of ty pe F L:iEN1, we have M , nil "-,,,+* return n , nil iff [M ] I N,n = a.
Hence denotational equality implies observational eq uivalence. 0

T he reason for the following terminology is given in C hap. 7.

Definition 5.3 A jump-point is a value t hat (for a given enviro nment)


denotes a fun cti on to Ans . 0

We note t hat there are two kinds of jump-point: t hunks and continua-
tions.
We emphasize/ t hat stacks and jump-point s are quite distinct con-
cepts. Only cont inuations fall into both categories . A stack such as
V :: K is not a jump-point b ecause it den ot es a pair. The sit uat ion is
summarized in F ig. 5.7. T he reade r should beware: other autho rs some-
times use t he word "continuation" to mean "j ump-point " or "stack" .
For example:

• [T hielecke, 1997aJ uses "cont inuat ion" to mean what we ca ll a jump-


point .

2es pecially t o readers fam iliar with t he CBV setting, wh er e all stacks are cont inuations, and
so t he current stack is usu ally ca lled t he "cu rr ent con tinuat ion"
104 CALL-BY-PUSH- VALUE

stacks

jump-points

thunks continuations

Figure 5.7. Continuations and Stacks

• [Hofmann and Streicher , 1997; Laird, 1998; Streicher and Reus, 1998],
which treat CBN as well as CBV , use "continuation" to mean what
we call a stack.

However, our definition of "cont inuation" follows the standard usage in


ML and Scheme (e.g. in ML, there is a type contA, which is a type of
continuations) .
Notice the semantics of CBV functions:

[A -tCBV B] = [U(A -t F B)] = ([A] x ([B] -t Ans)) -t Ans

As we said in Sect. 5.1, this is pr ecisely the traditional continuation-


passing semantics for CBV.

Stacks
As in Sect . 2.6.2, we wish to give a semantics for stacks fiB f-k K : C.
But in this case, the semantics is immediate, for we know from Sect . 5.4.3
that we can regard this as a value I' , nil : stk C f-k K : stk B, so it
denotes a function from [r] x [C] to [B].
This can be summarized by the slogan "in a continuation model, there
is a duality between values and stacks" .
Simple Models Of CBPV 105

5.4.6 Combining Control Effects With Other


Effects
This section is perhaps the most important in the cha pte r, as it leads
to t he Jump-With-Argument language of Chap. 7.
The continuation model in Sect . 5.4.5 generalizes. If we have any
CBPV model, we can obtain from it a continuation model for control
effect s.
As an example, consider the printing model for CBPV. We seek a
model for control effects together with print. The CK-machine seman-
tics will have the form M , K ~ m , N , L as in Sect . 2.4.2.
We fix an A-set Ans. This plays the same role as the set Ans in
Sect . 5.4.5. The denotational semantics for control effects wit h print is
then organized as follows:

• a value type (and hence a context ) denotes a set ;

• a computat ion type denotes' a set ;

• a value I' f-v V : A denotes a function from [r] to [A] ;

• a computation I' f-c M : B denotes a funct ion from [r] x [B] to the
carrier of Ans .

As exp lained in Sect. 2.8, we use CB PV as a metalanguage describing


the printing model. For example, we write U B for the carrier of an
A-set Band FA for the free A-set on a set A . W ith this notation , the
semantics of types is given by

[UB] U([B ] -+ An s) [FA]


[L iE/Ai] L iE/ [Ai] [TIiE/B i]
[A x A'] [A] X [A'] [A -+ B]
[s t k B] [B]

3 As in Sect . 5.4 .5, [1!] sho uld be thought of as shorthand for [s t k 1!].
106 CA LL-BY-PUSH- VA LUE

Semantics of te rms : some example clauses.

[r et urn V]( p, k) ([V]p)'( force k)


[M to x. N](p, k) [M ] (p, t hunk Aa.([N ] ((p, x M a), k)))
[t hunk M]p t hunk Ak.([M ]( p, k))
[f or ce V]( p, k) = k'force ([V] p)
[Ax.M](p, (a, k)) [M ]((p , x M a), k)
[V' M ] (p, k) [M ] (p, ([V ]p, k))
[l et st k x. M](p, k) [M ] ((p, x M k) , k)
[ch an ge s t k K . M ](p , k) [M ] (p, [K ]p)
[print c. M] (p, k) c * ([M ] (p, k))
[[.J to x. N -i: K ]p thunk Aa.([N]( (p,x M a), [K] p))
[V·:: K ]p ([V ]p, [K]p )
Proposition 50 (soundness) Suppose t hat M , K ~ m , N, L where

ff-CM : B r f-V K: stk B


ff-cN : C r f-v L: stk C

Then , for any environme nt p E [r] ,

[M]( p, [K ]p) = m * [N](p, [L]p) (5.3)


o
Corollary 51 (by t he analogue of P rop. 47) Suppose Ans has two ele-
ments a , b wit h the prop er ty that

m *a =1= m' *a for m =1= m ' E A *


m *a =1= m' *b for m ,m' E A*

(T his property is satisfied by the free A- set on a set of size ~ 2.) For a
countable set N and element n E N , write I N,n for t he fun ct ion from N
to Ans t hat takes n to a and everyt hing else to b.
Then for any closed gro und ret urner M of type FL- iEN1, we have
M , nil ~* m , return n, nil iff [M ]IN,n = m * a. Hence terms with t he
sa me denotation are observationally equivalent . 0

In a similar way, we can obtain a mod el for cont rol effects with re-
cursion. The semant ics of ty pes and terms are as above except t hat
we now understand t he metalingu ist ic U etc. as referring to t he Scot t
model rather than t he printing mod el. We need only rep lace t he seman-
tic equation for print by an equat ion for recursion .
Simple Models Of CBPV 107

5.5 Erratic Choice


5.5.1 The Language
We add to the language t he following errat ic choice constru ct
. .. T I- C M, : B ... iE I

r c
I- choose {. .. , i .M i, " ' } : B
where i ranges over I. According to tast e, we can allow I to be finit e,
countable, nonempty or an arbitrary set (although in the last case t he
set of terms will not be small). The meaning of choose {... , i .Mi, . .. }
is "choose some i E I , then execute Mi" : Thus to the big-step semantics
we add

choose {... ,i.Mi , .. .} .u- T


and to the CK-machine we add the transition
choose {.. . , i. M i , ... } K
~ Mi K
It can be proved that computations cannot diverge. Our formulation
of the big-st ep semantics does not allow us to express this fact , but the
CK -machine does allow us to express it :
P roposi tion 52 There is no infini te sequence of t ransit ions from any
configur at ion M , K . D

5 .5.2 Denotational Semantics


Computations
We seek a denotational semant ics for the language described in Sect . 5.5.1.
Since there is no divergence, we use a set model, and t he semantics of
valu es is given in Sect . 5.2.
Recall that, in the global st ore model of Sect . 5.3.2, a computation
typ e B denotes the set of behaviours that a computation r I- c M : B
can exhibit in a given environment and store. Our errat ic choice model
is somewhat simi lar, for B will denote the set of possible behaviours that
M can exhibit in a given environment . Thus M will denote a relation
from [r] to [B ], and we call this semantics relation semantics. The
semantics of types is given as follows.
• A pos sibl e behaviour of a comput ation of typ e F A is to return a valu e
V of typ e A. So F A denotes [A].
• A po ssibl e behaviour of a computation of ty pe IliEIB i is to pop
a par ti cular i E I and t hen exhibit som e possibl e behaviour of a
comp utation of typ e B i · So Il i EI B i denotes L i EI [B i].
108 CALL-BY-PUSH- VALUE

• A possible behaviour of a computation of type A ---+ B is to pop a


particular value V of type A and then exhibit a possible behaviour
of a comput at ion of type B. So A ---+ B denotes [A] x [B]'
• A value of type UB, when forced, might exhibit any of a range of
possible behaviours for a computation of type B. So U B denotes
P[B].
Semantics of terms-some example clauses:
(p,a) E [return V] iff [V]p = a
(p, b) E [M to x. N] iff for some a, (p, a) E [M] and
((p, x ~ a), b) E [N]
[thunk M]p {b E [B] : (p, b) E [M]}
(p, b) E [force V] iff bE [V]p
(p, (a, b» E [Ax.M] iff ((p, x ~ a), b) E [M]
(p, b) E [V 'M] iff (p, ([V]p, b» E [M]
(p,b) E [choose { ... , i.M i , ... }] iff for some i, (p,b) E [Mi ]
Proposition 53 (soundness and adequacy) For any closed compu-
tation M, we have
[M] = U [T]
MJJ-T
D

Proof For (;2) we induct on M JJ. T . For (~) we define subsets redA,
redk and red~ exactly as in Prop. 10, except that we replace the clause
for M E red:i!-by the following:
M E red'h iff for all b E [M] there exists T E redk such that M .lJ. T and
bE [T]. - -
We note that if T E redh then T E red~ (unlike in the proof of 10, the
converse is not apparentat this stage ofthe proof) . The rest of the proof
follows that of Prop. 10. D

Corollary 54 For any closed ground returner M, we have M JJ. return n


iff n E [M]. D
Notice the semantics of CBV functions:
[A ---+CBV B] = P([A] x [B])
This is the set of relations from [A] to [B] , a traditional nondeterministic
semantics for CBV. Notice too that for every computation type B, the
complete lattice P[B] is the denotation of B in algebra semantics-an
algebra for the powerset monad on Set is pr ecisely a complete lattice.
(This is an instance of Prop. 127 below .)
Simple Mod els Of CBPV 109
Stacks
As in Sect . 2.6.2, we wish to give semantics of stacks. Suppose we have
a stack fiB f-k K : C. We can see that , in a given environment p E [r] ,
the st ack takes a possible behaviour for a comput at ion of type B to a
ran ge of behaviours for a computat ion of type C. This is apparent in a
stack su ch as

IFboo 1 rLk []
. to
{true.
f 1
(return 3
5
I return 4) .. ' 1 ' F
.. nl. . nat
a se. return

Thus fiB f-k K : C denotes a relation from [r] x [B] to [C].

5.5.3 Finite Choice


We said in Sect. 5.5.1 that in the rule
... r f-c M, : B . . . iE I

r f-c choose {. . . ,i.Mi, " ' } : B


we can, if we like, restrict the set I that i ranges over to be finite (or
countable, or nonempty). Now t his effect clearly has a CBV model, in
whi ch A -7CBV B denotes not [A] -7 P[B] , as it previously did (up
to isomorphism) , but [A] -7 Pfin[B] , writing PtinX for the set of finite
subsets of X .
Our decomposition above of CBV errat ic choice semantics into CBPV
was based on the isomorphism
A -7 PB ~ P(A x B)

but there is no analogous isomorphism for A -7 PfinB. (See Sect. 12.2


for further dis cussion on modelling CBPV with finit e choice.)
This is a situation we shall see again in Sect. 6.9: a "basic" CBV
model (in t his exa mple, general erratic choice) exhibit s a decompositi on
into CBPV that a constrained model (finite errat ic choice) do es not.

5.5.4 New Model For May Testing


When we have both errat ic choice and divergence, t here are various
notions of observational equivalence we can consider, An important one
is the following.
Definition 5.4 Two computat ions r f-c M , N : B ar e may-testing
equivalent when for any ground conte xt C[.], we have
C[M] .l,l. return n iff C[N].l,l. return n
Similarly, we can define may-testing equivalence on values. o
110 CA LL-B Y-PUSH- VALUE

The following mod el, closely related to the lower (Hoar e) powerdo-
main and to the linear logic mod els of [Huth et al., 2000], appears to
interpret errat ic choice + divergence, using may-testing equivalence. It
has just come to light at t he t ime of writing, so t he details remain to
be worked out . We do not yet have a computational understanding in
terms of behaviours, so our treatment will be very bri ef.

Definition 5.5 Let R and S be posets. A relation ~ from R to S is an


opbimodule when r' ~ R r ~ s ~ s s' implies r' ~ s' , An opbimodule ~
is point wise ideal when for each r E R t he lower set {s E Sir ~ s } is an
ideal i.e. contains an upper bound for every finite subset . 0

In the may-testing model of CBPV, each valu e type (and hence each
conte xt ) and each computation type denotes a pos et.

• A value r f-v V : A denotes a pointwise ideal opbimodule from [r]


to [A].

• A comput ation r f-c M : B denotes an opbimodule from [I'] to [B ].

• A st ack fiB f-k C denotes an opbimodule from [r] x [B ] to [C].


We interpret L and x as disjoint uni on and cartesian product of posets.
To describe t he semantics of t he U connective, we require t he following.

Definition 5.6 Let R be a poset. For each element a E R we wri te ..J- a


for the set {r E R lr ~ R a }. A lower set of a poset R is finit ely generated
when it is of the form
..J- ao U . . . U ..J- an-l

We write fglow R for the set of finitely generated lower sets of R. 0

The key equat ions ar e

[UB] fglow[B]
[FA] [A]
[ITiEIBi] L iEI[Bi]
[A -+ B] [Af x [B]
The semantics of te rms is st raightforward. In par ti cular, we interpret

• diverge as t he empty relation

• J-Lx.M as t he least prefixed point

• choose {... ,i.Mi," ' } as t he uni on of [Mi]


Simple Models OJ CBPV 111

• an infinitely deep term as the union of denotations of its finite ap-


proximants.
To interpret computation type recursion, we notice that the category
OpBimod of posets and opbimodules is bilimit-compact, because every
(e ,p) pair from R to S is given by an order-preserving-and-reflecting
injection. Furthermore, the category of posets and pointwise ideal opbi-
modules is sub-bilimit-compact within OpBimod, so we can interpret
value type recursion.
We exp ect to be able to show that

[M] = U [T]
M4J.T

for any closed computation M, but this has not yet been done at time
of writing. This would imply that terms with the same denotation are
may-testing equivalent.
Notice the following.
• A value type always denotes a countable disjoint union of
join-semilattices. Compare this to our definition of predomain (Def. 4.8(2))
• For each valu e typ e A, the cpo of ideals of [A] is the denotation of
A in usual lower powerdomain semantics
• For each computation type B, the complete lattice of lower sets of
[B] is the denotation of B in usual lower powerdomain semantics.

5.6 Errors
The errors feature we consider here is much weaker than the exc ep-
tions feature ofML and Java. In particular, we do not provide a handling
facility.

5.6.1 The Language


We fix a set E of errors. We add to CBPV a command error e for
each e E E . The effect of this command is to halt execut ion, reporting
e as an "error message". Thus we add to the basic CBPV language the
rule

r f-c error e : B
Notice that error e can have any type, like diverge.
The big-step semantics now has two judgements M -U- T and M -U- e.
The rules are shown in Fig. 5.8.
112 CALL-BY-PUSH- VALUE

M[V/x] -I). e
let V be x. M -lJ. e

M -I).e M -lJ. return V N[VIx] -I). e


M to x. N-I). e M to x. N -I). e

M -I). e
force thunk M -I). e

Mi[V/x] -lJ. e
pm (i , V) as { .. . , (i, x) .Mi , ... } -I). e

M[V/x , V' /y] -lJ. e


pm (V, V') as (x , y).M -I). e

M -lJ. c M -I). A{.. . , i .Ni' ... } N i -I). c


i ' M -I). e i ' M -I).c

M -I). e M -I). Ax.N N[V/x] -I). c


V 'M -I). c V 'M -lJ. e

error c -I). e

Figure 5.8. Big-Step Rules for Errors in CBPV

Proposition 55 For every closed computation M , precisely one of the


following holds

• there exists unique T such that M -I). T and there do es not exist e
such that M -lJ. e

• there do es not exist T such that M -lJ. T and there exists unique c
such that M -I). e.

For the CK-machine, we first exte nd the class of configurations: a


configuration may be either of the form M , K as in Sect. 2.3.2, or of the
form c for e E E . We exte nd the class of terminal configur ations to be
Simple Models Of CBPV 113

the following:

return V nil
A{... ,i.Mi, ... } nil
AxM nil
e

and we add the transition

error e K

5.6.2 Denotational Semantics


Computations
We seek a denot ational semant ics for the language described in Sect. 5.6.1.
Since t here is no divergence, we use a set model. The semantics of values
is given in Sect. 5.2-the difficulty lies in the interpretation of comp u-
tations .
The semantics is very similar to our A-set sem anti cs for printing. (In
Sect . 9.7.2, we see that they are all algebra models.)

Definition 5.7 (cf. Def. 1.13) An E- set (X , error) consists of a set X


toget her with a fun ction error from E to X. We call X the carrier and
error the structure. 0

Here are some ways of const ructing E -sets (cf. Def. 1.14).
1 For any set X , the fr ee E -set on X has carrier X +E and we set
error e to be inr e.

2 For an i E I-indexed family of E-sets (Xi , error) , we set D iE](X i , error)


to have carrier D iE]X i and structure given pointwise: i' (error e) =
error e.
3 For any set X and E -set (Y, error) , we define the E-set X -+ (Y, error)
to have carrier X -+ Y and st ruct ure given pointwise: x ' (error e) =
error e.
Computation types denote E-sets and value typ es denote sets in t he
evident way: in particul ar F A denotes the free E -set on [A] and UB
denotes t he carrier of [B]. A computat ion r f-c M : B denotes a fun ction
from [r] to t he carrier of [B]' We omit seman tics of terms; the key clause
is
[error e]p = error e
114 CALL-BY-PUSH- VAL UE

Proposition 56 (soundness) • If M .u- T then [M] = [T ].

• If M .u- e t hen [M ] = error e.


o
Corollary 57 (by P rop. 55) For a closed ground returner M , we have
M .u- return n iff [M ] = inl n , and M .u- e iff [M] = inr e. 0

Not ice that we recover t he traditional semantics of CBV fun ctions:

[A -+ B] = [A] -+ ([B] + E)

Stacks
Just as for printing, a stack riB f-k K : 0 denotes a homomorphism
from [B] to [0] over [r]. Explicitly, if B deno tes (X , error) and 0
denotes (Y, error') , then K deno tes a function from [r] x X to Y such
t hat
[K](p, errore) = error'e
for all p and all e.

5.7 Summary
The easy part of all t hese models- the sem antics of values- was given
in Sect . 5.2, except for t he may-t esting model, where a valu e ty pe denot es
a poset and a valu e r f-V V : A denotes a pointwise ideal opbimodule
from [r] to [A]. In Fi g. 5.9 we summarize t he more difficul t part-the
semantics of computations and stacks. The set-based models are written
a bove the lines , the cpo- and poset-based models below the line.
Remember that , when giving semantics for global store + printing and
the semantics for control + printing, we use CBPV as a metalanguage
for the printing model: U means "carrier", F means "free A-set" . But
we can combine glob al st ore or control with any effect that we have a
model for, by understanding U and F as referring to this model.
For each effect , we see that the semantics of UF gives a monad in
the style of Moggi [Moggi, 1991]. It is rem arkable how each monad
decomposes into U and F in a specific way that fits t he ope rat ional
semant ics. In some ways, we have covered t he same ground of Moggi;
but t he key improvements are t hat
• we have included CBN as well as CBV;

• our language has ope rationa l semant ics.


Simpl e Models Of CBPV 115

effect comp . type denot es com putation r f-c M : B den ot es


pr inting A-s et functi on from [r] to W]
global sto re set function from 5 x [r] t o un
glob al st ore + print ing A- set function from 5 x [r] to W]
control set functi on from [r] x [~] to Ans
cont ro l + printing set fun ct ion fro m [r] x [~] t o Ans
erratic choice set rel ation from [r] t o W]
errors E-set fun ction from [r] to [B]
divergence cppo cont . fun ct ion from [r] to [~]
may-t esti ng poset opbimodule from [r] to W]

effect stack fiB f-k K : 0 denotes


print ing A- set homomorphism over [r] from W] t o [Q]
global store fun ction from [r] x W] t o [Q]
global st ore + printing A- set hom om orphism over 5 x [r] from W] t o [Q]
cont ro l fun cti on from [r] x [Q] to W]
cont ro l + printing fun ct ion from [r] x [Q] t o W]
errat ic choi ce relation from [r] x [~] to [Q]
errors E-set homomorphism over [r] from [B] to [0]
div ergenc e strict-in- 2nd-arg. cont . fun ction from [r] x [~] t o [Q]
may-t est ing opbimodule from [r] x W] to [Q]

effect U F UF =T
printing carrier free A- set A* x -
global store 5-+- 5x- 5 -+ (5 x - )
global st ore + printing U (5 -+-) F(5 x - ) U (5 -+ F (5 x - ))
contro l - -+ Ans - -+ Ans (- -+ Ans) -+ Ans
control + printing U (- -+ Ans) U(- -+ Ans) U (U (- -+ Ans) -+ Ans)
erratic choice -p -p
errors carrier free E-set - +E
di vergence lift lift
may-t est ing fglow fglow

effect -+ IT iI=f
printing -+ IT i Ef
global st ore -+ ITi Ef
global store + printi ng -+ ITi E f
cont ro l x L iEf
control + printing x L i Ef
er ratic choice x L i Ef
errors -+
n.;
ITi "'!
div ergen ce -+
op
may-testing - x - L i Ef

Figure 5.9. Summar y of sim ple C BP V mod els


116 CA LL-B Y-PUSH- VA LUE

effect [A --tCB V B ] = [U(A --t F B )] [A --tC B N m = [UA --t m


global store 5 --t ( [A] --t (5 x [B])) (5 --t [A]) --t W]
control ([A] x ([ B ] --t Ans )) --t Ans ([A] --t Ans ) x W]
erratic choice P ([A] x [B]) (P[A)) x [B]

Figure 5.10. Induced semant ics for CB V and CBN fun cti on ty pes

Looking at a few examples, we see in Fi g. 5.10 t ha t we recover tradi-


tiona l sem antics for CBV, and we obtain stran ge-looking semant ics for
CBN. As st ated in Sect . 5.1, the CBN semantics for global sto re was
presented in [O'Hearn, 1993], while the CBN sem antics for cont rol ap-
pear ed in [Streicher and Reus, 1998]. We can see that CBPV provides
an explana tion of these appar ently mys terious models.
Chapter 6

POSSIBLE WORLD MODEL


FOR CELL GENERATION

6.1 Cell Generation


This chapter has two parts. The first part (Sect . 6.1-6.5) presents the
language and operational semantics, whereas the second part (Sect. 6.6-
6.10) presents a denotational model using po ssible worlds. The pointer
game semantics in Ch ap. 8 models cell generation too, and therefore
Chap. 8 presupposes Sect. 6.1-6.3.
In Sect. 5.3, we looked at semantics of global storage cells. But most
programming languages provide facilities for generating new cells (i.e.
memory locations) during execut ion. In such a language there may be ,
at one time, 3 cells storing a boolean and 1 cell storing a number , and a t
a later time, 5 boolean-storing cells and 6 number-storing cells, bec ause
2 new boolean-storing cells and 5 new number-storing cells have been
generated. Consequently, to describe the state of the memory at a given
time, we require two pieces of information:

• the uiorld , which tells us how many boolean-storing cells, how many
number-storing cells, et c., ar e in existe nce

• the store , which tells us what values these cells are storing.

These two pieces of information together ar e called a world-store.


We stress that the world can only increase: new cells ar e generated
but (at least in principle) none are ever destroyed. Writing w for the
earlier world and w' for the later world, in the above example, we say
that w ::::;; w' . We write W for the pos et of worlds.

117
P B Levy, Call-By-Push-Value
© Springer Science+Business Media Dordrecht 2003
118 CALL-BY-PUSH- VALUE

6.2 The Language


We add ref types to CBPV, giving the following type system :

A··= U'B LiEIAi I1 IAx A I ref A


B··= FA TIiEIBi I A -+ B
As in ML, a value of type ref A is a cell (i.e. a memory location) that
stores a value of type A. For example, a valu e of type ref ref bee 1 is
a cell storing a cell storing a boolean.
Maintaining our convention that commands are prefix es, we add the
following terms.

Assigning to a cell
r f-v V : ref A r f-v W : A r f-c M : 11
I' f-c V := W. M : B

This computation replaces the current contents of the cell V with W ,


and then executes M.

Reading a cell
r f-v V : ref A r , x : A f-c M : 11
r f-c read V as x. M : B

This computation binds x to the cur rent contents of the cell V (in
other words , substitutes the current contents of V for x) , and then
executes M .

Generating a new cell


r f-v V : A r ,x : ref A f-c M : 11
r f-c new x := V. M
This computation generates a new cell x, initially storing V , and then
executes M. We can extend this to recursiv e initialization, where V
is allowed to mention x, as follows:
r , x : ref A f-v V : A r , x : ref A f-c M : 11
r f-c newrec x := V ; M

Mor e generally still, we can consider mutually recursiv e initialization


newrec Xo:= Vo , . .. , X n- l := Vn - 1 . M . However, we will not treat
this.
Possible World Model For Cell Generation 119

Equality of cells One might expect the primitive for equality testing
to be
r f-V V: ref A r f-v V' : ref A
r f-v V = V' : bool
But this is a complex value (in the sense of Sect. 3.2) . So, for the
sake of operational semantics, we take instead

r f-v V: ref A r f-v V' : ref A r f-c M : Ii r f-c M ' : B


r f-c if V = V' then MeIse M ' : B

6.3 Operational Semantics


6.3.1 Worlds
As computation proceeds, new cells are generated. The number of
cells presently in existence, together with their type, is described by a
world.

Definition 6.1 1 A world W is a finite multiset of value types, i.e. a


function from the set valtypes of value types to N, such that

L WA < 00
AEvaltypes

Informally, WA is the number of A-storing cells in the world w. The


condition ensures that the total collection of cells in a world is finite.

2 Using the notation of Sect. 1.4.1, we write cells W for the finite set
l:AEvaltypes$WA , the set of cells in w.

3 The empty world 0 is given by

oA = 0 for all A.

4 Let W be a world and let A be a value type. We use the phrase W


extended with an A-storing celll to mean the world w' defined by

ifB = A
otherwise

The new cell l is then defined to be W A.

5 Let wand w' be worlds. We say that W ~ w' when

WA ~ w~ for all A.
120 CALL-BY-PUSH- VALUE

6 We write W for the poset of worlds regarded as a category. If w ~ x,


we write ~ for the unique morphism from w to x .
o
The judgements that we use for cell generation are more general than
before: we want, for each world w, a class of w-values and a class of
w-computations. These are terms that can explicitly refer to the cells in
w. We write these judgements
wlf f-v V: A wlf f-c M: B
where w is a world. (Where w = 0, we sometimes omit it.) We modify
each typing rule by adding wi to each premise and to the conclusion.
Additionally we introduce the rule

where i E $WA (6.1)


wlf f-v cell Ai : ref A
for explicit mention of a cell.
Proposition 58 f w ~ w' then every w-value is also a w'-value and
every w-computation is also a w'-computation. 0

6.3.2 Stores
The world tells us only how many cells there are of each type, not
what they contain. This latter information is provided by the store.
Definition 6.2 1 Let w be a world. A w-store is a function associating
to each pair (A, i), where A is a value type and i E $WA, a closed
w-value wi f-V VAi : A. We write it
(... , cell Ai f---7 VAi ,"')

2 A world-store is a world w together with a w-store s.


o
The operations on stores are similar to the store-handling constructs
in the language:
Definition 6.3 Let (W,8) be a world-store and let A be a value type.
reading If l is an A-storing cell in w, we use the phrase the contents of
celll in 8 to mean the function 8 applied to (A, l).
assignment If l is an A-storing cell in wand wi f- V : A, we use the
phrase 8 with celll assigned V for the w-store 8 ' which is the same
as 8 except that
8 ' (A , l ) = V
P ossible World Model For Cell Generation 121

cell generation, with recursive initialization Supppose w' is w ex-


tended wit h an A-storing cell i, and we have a w-store s is and a w'-
value V of ty pe A . (In t he nonrecursive spec ial case , V is a w-value.)
T hen s exten ded wit h a cell l sto rin g V is t he w'-store in which
• each w-cell stores t he same value as in s (except t ha t in s' it is
regarded as a w'-value rather t ha n a w-value)
• t he new cell l sto res V .
D

6.3.3 Operational Rules


The operational semantics of our dynamically generate d store is simi-
lar to t he operational semant ics of global store in Sect. 5.3.1. We define
a relation of the form w,s, M .J,l. w' , s' ,T where
• w, s is a world-store;
• M is a closed w-computation;
• w', s' is a world -store such that w' ~ Wj

• T is a closed te rmina l w'-computation.


We repl ace each rule in Fig. 2.2 of the form (2.1) by

and we add t he following ru les:


w , s, M [V/ x] .J,l. w' , s' ,T
w,s, r e ad cell Ai as x. M .J,l.w',s' ,T

V is t he conte nts of A-st or ing cell i in s

w ,s',M.J,l. w' ,s', T


w,s, cel lA i := V. M .J,l. w' , s' ,T

s' is s with A-storing cell i ass igned V

w' , s' , M[cell Ai/ x] .J,l. w" , s" ,T


w,s, newr e c x := V. M .J,l. w", s", T

(w' ,s') is (w, s) exte nded with a cell i storing V[cellAi/ x]


122 CALL-BY-PUSH- VALUE

w, s, M -U- w', s',T


w ,s,if cellAl = cellAl then MeIse M' -U-w' ,s',T

w, s, M' -U- w', s' , T


, (l =/: l')
w,s ,if cellAl = cellAl then MeIse M' -U-w',s',T
Similarly, we can adapt the CK-machine to include these constructs.
Of course, this requires a class of w-stacks for each world w, written
wlrlB f-k K : c.
6.3.4 Observational Equivalence
Definition 6.4 Given two computations wlf f-c M ,N: B , we say that
M c::= N when for every ground w-context C[·] and every w-store sand
every n we have
:Jw', s'(w, s , C[M] -U- w', s', return n)
iff
:Jw', s' (w , s, C[N] -U- w', s' , return n)
We similarly define c::= for values. D

Some important observational equivalences are


new x := V. M XM (6.2)
new x := V. new y := W . M new y := W. new x := YV. M(6.3)
using the conventions of Sect. 1.4.2.

6.4 Cell Types As Atomic Types


The definition of "world" depends on the syntax of types. This
presents a problem when we move between different languages with dif-
ferent syntax of types, and we wish to show preservation of operational or
denotational semantics. Furthermore, there are (in the infinitely wide
language) uncountably many ref types and hence uncountably many
worlds, and we shall see in Sect. 6.8 .3 that this is undesirable. In addi-
tion, the ref type constructor is badly behaved in the sens e that A ~ B
do es not imply ref A ~ ref B .
A way of rectifying all these problems is to abolish the ref type
constructor. Instead, we fix a countable set N , whose elements we call
cell types, together with a function ¢ from N to the set of value types
generated from N . This set is defined by
A ..= UB I I:iEIAi I 1 I A x A I refe
B ..= FA I ITiEI B i I A ---+ B
Possibl e World Model For Cell Generation 123

where C ranges over N .


A value of type re f e is a cell storing valu es in ¢ (C ). We do not
requ ire ¢ to be inject ive or surjective, so we might have , for example,
two types of boot-storing cells and no type of nat-storing cells. On ly
cells in the same cell type can be tested for equality. A world is now
defined to be a finite multiset in N . This defin it ion does not involve
syntax of types, and it makes the poset of worlds countable because N
is assumed countable.
We mod ify the typing rules in Sect. 6.2 for reading, assignment, cell
generation and equa lity testing: we replace ref A by ref e and A by
¢(C) throughout . We likewise modify t he typing ru le (6.1) for exp licit
mention of a cell:

where i E $we
wlf f-v cell c i : ref e

To see t he advantage of this formulation when we are dealing with


translation between la nguages, consider the translation from CBV to
CBPV. If we take CBV with (N , ¢)-cell generation, we can translate it
into CBPV with (N , ¢') -cell generation, where ¢'(C) is defined to be the
translation of ¢( C) . In both languages, a world is, by definit ion , a finite
multiset in N . SO preservation of operational semantics is straightfor-
ward to describe. We do not need to consider whether the translation is
injective on types, as we would if worked with ref A types.

6.5 Excluding Thunk Storage


In Chap. 5, we studied vario us effects in the absence of divergence.
This enabled us to present simple set -based semantics and to avoid a
difficult adequacy proof. But this convenient sty le of exposit ion is im-
possible for a language that stores thun ks , because, as Landin showed,
recursion can be encoded in terms of thunk storage.
We will t herefore define the data type gene rated by N to be t he fol-
lowing class

and we divide our exposit ion into 2 stages.


1 For most of the chapter, we will model cell generation wit h the "no
thunk storage" constraint : ¢( C) is required to be a data type for
each C E N . With this constraint , we can show

Proposition 59 For any world-store w , S and closed w-computation


M , there is a unique w' , s' , T such that w, s , M .lJ. w', s' , T . 0
124 CALL-BY-PUSH- VALUE

2 In Sect. 6.10 we will explain how to adapt our approach to the general
"thunk storage" situation, where ¢( C) can be any type.

Even the "no thunk storage" constraint allows storage of cells, so it is


more liberal than languages allowing storage of ground values only.

6.6 Introduction
6.6.1 What Is A Possible World Semantics?
We now turn to the real subject of the chapter, denotational semantics
using possible worlds.
How can we provide a denotational semantics for a language with cell
generation?? One plausible approach is to use the global store semantics
of Sect. 5.3, replacing the set of stores by the set of world-stores. How-
ever, by contrast with the store in Sect . 5.3, which can change in any
way at all, the world-store is constrained in the way it can change by
the fact that the world can only increase. Our goal is to provide a model
that, unlike the global store model, embodies this important constraint.
The key idea which leads to such a model is that of possible worlds:
a value type, instead of denoting just one set (or cpo) , has a different
denotation in each world. For example, refe would denote the 3-element
set $3 in a world w where there are 3 C-cells, but the 5-element set $5 in
a world w' where there are 5 C-cells. We write [A]w for the denotation
of A in the world w .
The various sets denoted by a type A are related. In the above ex-
ample, [C]w is clearly a subset of [C]w' . In general, whenever w ~ w',
there will be a function [A]~1 from [A]w to [A]w'. These functions
satisfy the equations

[A]~a a

[A]~l1a [A]~;,([A]~la) for w ~ w' ~ ui"

In summary, every value type A denotes a covariant functor from W


to Set. For sum, product and cell types, this is all straightforward.
Denotations at ware given by

[I:i EIAi]W I:iEI[Ai]w


[A x A']w [A]w X [A']w
[refc]w $we

while denotations at ~1 are given in the obvious way.


Possible World Model For Cell Generation 125

6.6.2 Contribution Of Chapter


In this cha pter , we present a poss ible world semantics for general
storage. It is t he second denotational model for general storage, t he
first being t he pointer game semantics of [Abramsky et al. , 1998]. A
number of possible world models have been described in the literature
[Ghica, 1997; Moggi, 90; Oles, 1982; Pitts and Stark, 1993; Reynolds ,
1981; Stark, 1994], but these (with t he exception of [Ghica, 1997], which
models pointers in a CBN setting) interpret storage of gro un d values
only.
T he model we will present differs from t hese in several resp ect s. For
example, in t hese models a type denotes a functor not from W but from
t he larger category of world injections or t he even larger category of store
shapes [Oles, 1982]. So t his chapter is not the usual story of "t rad itional
CB N and CBV semant ics decompose into CBPV semantics" , at least not
in a straight forward way- the relationships between t he vario us models
ar e rather su btle. For t hat reaso n, it is probably wise for readers familiar
with older models to regard t he model in t his chapter as essentially
different; we dis cuss this in Sect . 6.9.

6.6.3 Stores
We writ e Stu for the set

x [¢>(C)]w
(0, I) E cells w

We use the x symbol to emp hasize that the product is finite. An element
of 3w is called a semantic w-store, and a syntactic w-store (map from
cells to values) denotes a semantic w-store. But in the abs ence of thunk
storage, this disti nction is not so impor tant , because

Proposition 60 For every data type D and world w, the funct ion [- ]
from the set of closed w-values to to [D]w is a bijection. Hence t he
funct ion [-] fro m t he set of syntactic w-sto res to Siu is a bijection. D

Often, we will speak informally of a "w-store", without spec ifying "se-


mantic" or "syntact ic" . It is clear t hat t he 3 operations defined on
syntactic world-stores in Sect . 6.3.2 (reading , ass ignment and cell gen-
eration) have evident an alogues for semantic world -stores .
Notice that if w ~ w' , t here is no canonical fun ction 3 w • 3 w'
or 3w' • Siu , so 3 is neither covariant nor cont ravariant. By con-
trast, when we allow storage of ground values only, there is a canonical
fun ction 3w' • S u: given by restriction, so 3 is cont ravariant .
126 CALL-BY-PUSH- VALUE

That is why our model is so different from the ground storage models
menti oned in Sect . 6.6.2.

6.6.4 Possible Worlds Via CBPV Decomposition


One of our heuristics for designing a CBPV semantics is to find a
CBV semantics and look for the CBPV decomposition of --+CBV . Such a
CBV semantics for cell generat ion in [Levy, 2002] and was ind ep endently
considered by O'He arn. It uses the following int erpret at ion:

[A --+CBV B] w = Ilw' :>-w(Sw' --+ [A]w'


--+ L.wl/:>-w'(Sw" x [B] w"))
z-: z-: (6.4)
The intuition behind (6.4) is as follows. Suppose V is a CBV fun ction
in world Wi it should denote an element of t he LHS of (6.4). Now V
can be applied in any future world-store (w' , s' ), where w' ~ wand s'
is a w'-store, to an operand which is a w'-value of typ e A . It will then
change the world-store to (w" "~s" ) where w" .> w' and s" is a w"-store,
and finally ret urn a w"-value of type B . The RHS of (6.4) precisely
describes this nar rative.
The CBPV decomposition of A --+CBV B as U(A --+ F B) is immedi-
ate ly apparent in (6.4) :

Ilw' :>-w(Sw' --+ [A]w' --+ L.wl/ :>-w'(S w"x [B] w"))
z-: U (A --+ ;-- F B)
This suggest s that a computat ion type will, like a value type, denote a
different set in each world, and that these sets are given by

[FA] w L.w' :>-w(Sw'


z-:
x [A] w') (6.5)
[A --+ B]w [A]w --+ [B] w (6.6)
[UB] w Ilw' :z-:>-w(Sw' --+ [B] w') (6.7)
How are we to underst and these sets intuitively? In t he storage model
of Sect. 5.3.2, we said that [0] is the set of behaviours for a computation
of type 0 in a given store and environment. So it is reasonable to expec t
[O]w to be the set of behaviours for a w-computation M of type 0 , when
executed in a given w-store s and w-environment p. Let us now read the
above equat ions in this light.
• If M has typ e FA , t hen it terminates in st ate (w' , s' ) for some w' ~ w ,
returning a w'-value V .
• If M has type A --+ B then it is (equivalent to) a A-abstraction,
which pops a w-value V and then , dep ending on V , behaves as a
w-comput at ion of type B .
Possible World Model For Cell Gen eration 127

• Similarly, if M has type ITiE1Bi, it is (equivalent to) a A-abstraction,


which pops an i E I and then, depending on i , behaves as a w-
computation of type B i . So we will have the equation

• If V is a w- val ue of type U B then it can b e forc ed in any state (w' , s') ,


where w' ~ w , and will then behave as a wi-computation.

As an example, suppose ¢(C) = nat , so a value of type refe is a cell


storing a natural number. Let w contain a single C-celll , represented as
cell 0, and consider the following w-value of type U(refe ---+ Frefe) :

thunk ( AX.
read cell 0 as y.
read X as z .
ceIIO := z.
x :=y.
new w := y + (3 x z).
return z )

This can be forced in any world-store (w' , s') , where w' ~ ui. It first
pops a celll' in ui', Then it changes the world-store to (w" , s") where

• ui" is w' exte nded with a C-celll" ;

• writing y and z for the contents of cells land l' in s' resp ectively, s"
is the w"-store in which
l stores z
r stores y
I" stores y + 3 x z
every other cell stores wha t it stored in in 8', regarded as a w"-value

and returns z.

6.7 Denotational Semantics


6.7.1 Semantics of Values
Suppose we have a value wlf f-v V : A. For each world w' ~ wand
each environment p of closed wi-values, we obtain, by substitution, a
closed wi-value of type A. Thus V will denote, for each world w' ~ ui,
a function [V]w' from [r]w' to [A]w'. These functions are related: if
128 CA LL-B Y-PUSH- VALUE

w ~ w' ~ w" then


[r] w' ~ [A]w '

(6.8)

[ f ]W '1- [A]w"
[V]w"
must commute. In the case t ha t w = 0, we can summarize this by saying
that V denotes a natural transformation from [r] to [A].
Informally, (6.8) says that if we have an environment p of closed w ' -
values, substitute into V and then regard the result as a closed w"-value,
we obtain the same as if we regard p as an environment of closed w"-
values and substitute it int o V .
In particular, a closed valu e wi f- V : A deno tes a family {awl } WI ~ W '
where awl E [A]w' for each w' ~ w and aw" = [A] ~"awl for each w ~
I

w' ~ w" . Such a famil y corresp onds to an element of [A]w. So our


earlier intuition that [A]w should be thought of as t he set of denotations
of closed w-values agrees with our interpretation of f-v.

6.7.2 Semantics of Computations


Suppose we have a w-computat ion w Jr f-C M : B . Now M can be
executed in any w-store a nd w-environment , so we might t hink that M
sho uld denote a fun cti on from 8w x [r]w to [B]w (the la t ter set , we
recall , being the set of behaviours of a w-comp utation). Bu t t his is not
sufficient, becaus e M ca n also be exte nded to a w'-computation, for any
w' ~ w, and then executed in any w'-store a nd w'-environment . So for
each w' ~ w , we want a fun ction [M]w ' from 8 w' x [r]w ' to [B]w ' .
What is perhaps sur prising is that , unlike the semantics of values , we
do not impose any naturality const raint relating [r]w ' across different
w' . Such a naturality const raint cannot b e formulated , be cause Su: is
not functorial in w .

6.7.3 A Comput ation T ype D enot e s A


Contravariant Funct o r
If we now attempt to write semantic equ ati ons for t he various te rm
construc tors, all are straightforward except for two: n ew and sequencing.
We look at the former. For simplicity, we will suppose t hat I' is empty.
Suppose t hat f-V V : ¢(C ) and x : r ef e f-c M : B . We wish to
describe the denotation of n ew x := V. M in t he world-store (w, s )- this
denotation should be an element of [B]w . First , we extend (w, s ) with
Possible World Model For Cell Generation 129

a C-cell l initialized to [V]w , giving a world-store (w', s'). Then, we


look at the denotation of M (with x bound to the new cell l) in the
world-store (w', s')-this denotation is an element of [B]w'. How can
we obtain an element of [B]w, as required?
The answer is that [B] must provide extra information. If w ~ w',
then [B] must provide a function [B]~, from [B]w' to [B]w. These
functions should respect identity and compositions:

[B]~b b
[B]~lIb [B]~I ([B]~:,b)

In summary, a computation type B denotes a contravariant functor from


W to Set.
As we have done with the rest of the semantics, we would like to
provide some intuitive understanding of these functions. A rough idea
is that, for w ~ w' , a w'-behaviour can be turned into a w-behaviour
that first generates additional cells. The contravariance is reminiscent
of the structure * in the semantics of printing. There, the role of * in
[B] = (X, *) was to "absorb" printing into computations of type B .
Here, the role of [B]~, is to "absorb" cell generation into computations
of type B.
The contravariant functors denoted by computation types are given
as follows.

• We have already said that [FA]w is ~wl>-w(SW' X [A]w'). Conse-


quently, if w ~ x then [F A]x ~ [F A]w. Y

• The denotation of TIiEIBi is given pointwise. Since each [Bi]w is


contravariant in w it is clear that TIiEI[Bi]w is contravariant in w.

• The denotation of A -+ B is given pointwise. Since [A]w is covariant


in wand [B]w is contravariant in w, it is clear that [A]w -+ [B]w is
contravariant in w.

6.7.4 Semantics of Stacks


As in all of our denotational models, we with to interpret stacks
wlrfB I- k K : C as well as values and computations. Suppose we have
a stack wlflB I- k K : C. Then for any w' ~ wand any w'-environment
P E [r]w ', it transforms a behaviour of a w'-computation of type B into
a behaviour of a w'-computation of type C. As we argued in Sect . 5.3.2,
this transformation is not dependent on the initial store, so K will de-
note, for each w' ~ w, a function [K]w ' from [r]w ' x [B]w to [C]w.
130 CA LL-BY-PUSH- VALUE

These fun ctions are related: if w ~ w' ~ w" t hen

W' [r]w' X [B]w' ~ [C]w'


~
\

[r]w' X [B]w" [Q):;;:,

~
"," dlJIiJ" [r]w" X
[ ] "
[B]w" ~ [C]w"
(6.9)
must commute . In t he case t ha t w = 0, we can summa rize t his by saying
t hat K denot es a dinatural transformation from [r] x [B ] to [C].
Informally, (6.9) says t hat running against K , in an environment p E
[r]w' , a w'-computation that first generates cells up to w" and then
behaves as b E [B] w" is equivalent to first generating the cells and
t hen running the remaining computat ion agai nst K . This is similar to
t he requirement in t he printing mod el that [K ] preserve the printing
structure because running print c. M again st K will first print c and
t hen run M against K.

6.7.5 Summary
We now summarize t he denotati onal sema ntics of CBPV with cell
generation, with no t hunk storage . The seman ti cs is organized as follows.

• A value ty pe (an d likewise a data ty pe and a context ) denotes a


covariant fun ctor from W to Set.

• A value w lr I- V V : A denotes, for each w' ~ w", a fun ction [V]w'


from [r] w' to [A]w' such t hat diagram (6.8) commutes for w ~ w' ~
w" .

• A computat ion typ e denot es a cont ravariant functor from W to Set.

• A computation I' I- c M : B denotes, for each w, a fun ction from


8w x [r]w to [B] w.

• A computation wlr I- c M : B deno tes, for each w' ~ w a fun cti on


from 8w' x [r]w' to [B ]w'.

• A stack wjrl B I- k K : C denotes, for each w' ~ w, a fun cti on [K]w'


from [r]w' x [B ]w' to [C]w' such t hat diagram (6.9) commutes for
w ~ w' ~ w".
Possible W orld Model For Cell Generation 131

T he semantics of types is given by


8w X [D] w
(D , l) E cells w
[UB]w I1w':>-w(8w'
z-:
---+ [B] w' )
[L: iEI Ai] W L:iEI[Ai] w
[A x A']w [A] w X [A']w
[ref c] w $wG
[F A] w L:w' :>-w(8w'
s-:
X [A] w)

[I1 iEI B i] W I1 iEI[ B i] w


[A ---+ B ]w [A] w ---+ [B]w
Some examples of semantics of terms:
[return V ]wsp = (w, s, [V] wp)
[M t o x. N ]wsp =
pm [M]wsp as (w' ,s',a) . [B] ~/([N] w' s' ([r] ~/ p ,x f---7 a))
[thunk M ]wp AW'. AS' .([M]w' s' [r]~/p)
[force V ]wsp s'w' [V] wp
[AxM]wsp Aa.( [M]ws(p , x f---7 a))
[V 'M]wsp ([V ]wp) ' ([M ]wsp)
[V := W. M ]wsp [M]ws' p
where s' is s with A-storing cell [V] wp assigned [W] wp
[read V as x. M ]wsp = [M ]ws(p, x f---7 a)
where a is the contents of A-storing cell [V] wp in s
[newrec x := V. M ]wsp = [B] ~/[M] w' s' ([r] ~/ p,x f---7 1)
where (w' , s' ) is (w,s) extended with cellI storing [V] W' ( [r] ~/ P ,X f---7 1)
Proposit ion 61 (So u n d n ess) Suppose w, s, M JJ- w', s', T, where M
and T have type B . Then [M] ws = ( [B]~, )([T] w' s'). D

The contravariance of [B] is essential in formulating t his statement, just


as, for t he printing semantics, t he structure map of [B] is essential in
formulating Prop. 18.
Corollary 62 (by Prop. 59) If M is a closed gro und w-returner then
w, s, M JJ- w', s', return n iff [M]ws = (w' , s', n) . Hence t erms with the
same denotation are observationally equiva lent. D

6.8 Combin ing Cell Generation With Other


Effects
6.8.1 Introduction
The model for cell generation in Sect. 6.7 generalizes . If we have any
CBPV model, we can obtain from it a mo de l for cell generation. We
132 CA LL-B Y-PUSH- VAL UE

show two examples of t his cons truction: st arting with t he A-set model
for printing, and starting with t he Scott mod el for divergence.

6.8.2 Cell Generation + Printing


When we add b oth cell generation and printing to CBP V, the big-st ep
semantics will have t he form w , S , M JJ. m , w' , s',T. T he deno tati onal
semant ics is organized as follows, writing ASet for t he category of A-
sets and homomorphisms.

• A value type (and likewise a data typ e and a context ) deno tes a
covariant fun ctor from W to Set.

• A value wlr I- v V : A denot es, for each w' ~ ui"; a fun ction [V]w'
from [r]w' to [A]w' such that diagram (6.8) commutes for w ~ w' ~
ui" ,

• A computat ion ty pe denotes a cont ravariant fun ct or from W to ASet.

• A computation r I- c M B deno tes, for each w , a fun ction from


Sw x [r]w t o [B] w.

• A computation wlr I- c M : B deno tes, for each w' ~ w a fun ction


from Sw' x [r]w' t o [B]w' .

• A stack wlq B I- k K : C denot es, for each w' ~ w, a fun cti on


[K] w' from [r] w' x [B ]w' to [C]w' su ch t hat [K]w' (p, c * x ) =
c* ([K] w(p, x ))- i.e. [K] w is homomorphic in its second argument-
and such that diagram (6.9) commute s for w ~ w' ~ ui" ,

We use infinitely wide CBPV as a metalanguage describing the print-


ing model, as explained in Sect . 2.8. For example,we wri te FA for the
free A-s et on the set A , and we wri te UB for the carrier of t he A- set B.
Wi th t his not ation, t he semantics of ty pes is given by

[UB]w UTIwl >-W (Sw' -T [B] w' )


;/

[FA]w F Lw' >-w(Sw'


z-:
x [A]w')
[TIiE/Bi]w TIiE/[B i]w
[A -T B]w [A]w -T [B]w
Poss ible World Model For Cell Gen eration 133

Some examples of semant ics of terms:

[return V]w sp = return (w, s, [V]wp)


[M to x. N ]wsp =
[M]w sp to (w' , s' ,a) . [B] ~/([N]w' s'([r] ~/P'x I-t a))
[thunk M]wp thunk AW'.AS'.([M] w' S ' [r]~/ P)
[force V]w sp s'w' force [V] wp
[AxM]wsp Aa.([M] ws(p, x I-t a))
[V'M]wsp ([V]wp) '([M]wsp)
[V := W. M] wsp [M]ws'p
where s' is s with A-storing cell [V]wp assigned [W]wp
[read V as x. M] wsp = [M]ws(p , x I-t a)
where a is the cont ent s of A-storing cell [V]wp in s
[newrec x := V. M]wsp = [B] ~,[M] w' s'([r] ~/p,x I-t i)
where (w', s' ) is (w, s ) extended with cell i storing [V] W'([r] ~IP , x I-t i)
[print c. M]w sp = c * ([M]w sp)

Proposition 63 (Soundness) Suppose w, s, M -U- m, w' ,s', T , where


M and T have type B . Then [M]w s = m * ([B] ~ , )([T]w' s' ). 0

Corollary 64 (by the an alogue of Prop. 59 for printing) If M is a


closed ground w-ret urner then w, s, M -U- m , w', s' , return n iff [M]w s =
(m , w', s' , n). Hence te rms with the same deno tation ar e observat ionally
equivalent . 0

6.8.3 Cell Generation + Divergence


We add dive rgence and recursion to CBPV with cell generat ion (with
no thunk sto ra ge). The semanti cs is organized as follows:

• A data type denotes a covariant functor from W to Set, so 8 w is a


set for each world w .

• A valu e type (and likewise a cont ext) denotes a covariant fun ctor
from W to Cpo.

• A value wlr f-v V : A denotes, for each w' ~ w", a continuous func-
tion [V]w' from [r]w' to [A]w' such that diagram (6.8) commutes
for w :::; w' :::; w" .

• A computation typ e denotes a cont ravariant functor from W to Cpo''


(the category of pointed cpos and strict cont inuous fun ctions).

• A comput at ion I' f-c M : B denotes, for each w , a cont inuous fun ction
from 8w x [r]w to [B]w.
134 CA LL-B Y-PUSH- VAL UE

• A computation wif f-c M : B deno tes, for each w' ~ w a fun ction
from 8 w' x [r]w' to [B ]w' .

• A st ack w jf jB f-k K : C deno tes, for each w' ~ w , a continuous


fun ction [K ]w' from [r]w' x [B]w' to [C]w' such t hat [K ]w' (p,..l ) =
..l-Le. [K ]w is strict in its second ar gument- and such t hat diagr am
(6.9) commutes for w ~ w' ~ W".

The equat ions giving t he semantics of types and terms ar e exactl y the
same as in Sect . 6.8.2, except that we now interpret the metalinguistic
CBPV const ructs as referring to the Scott model rather than the printing
model.

Proposition 65 (Soundness/Adequacy) 1 Suppose M has type B


and w,s, M -U-w' , s' ,T. Then [M]ws = ([B] ~/)([T] w' s' ).

2 Suppose w, s, M diverges. Then [M]ws = ..l.


o

Proof (in t he style of [Tait, 1967]) (1) is st raight forward. For (2), define,
by mutual inducti on over ty pes, t hree families of rela tions:

• for each A and w, a relati on ~Aw between [A] and closed w-values,
such that {a E [A] : a ~ Aw V} is admissible and lift-reflecting, and
a ~ Aw V and w ~ x implies ([A] ~)a ~ Ax V

• for each Band w, a relation ~ kw between [B]w and triples w', s, T


where w' ~ w, s E 8 w' and T-is a terminal w'-computation, such
that {b E [B]w : b ~1Jw x , s, T} is admissibl e and contains ..l, and
b ~hWI x, S, T and w ~- w' implies ([B] ~/)b ~hw x, s, T

• for each B and w, a relation ~~w be tween [B]w and t riples w' , s, M
where w' ~ w, s E 8w' and M is a closed w'-computation, such
t hat {b E [B]w : b ~ 1Jw x, s , M } is admissible and contains ..l, and
b ~~WI x , S, M an d w ~ w' implies ([B]~/) b ~~w x , s , M .
Possible World Model For Cell Gen eration 135

The definition of these relations proceeds as follows:


a ~uliw thunk M iff for all x ~ wand s E Sx,
s' x' force a ~'k x x, s, M
a ~~ A. (i , V ) iff a = (i , b) fo~ some i E I and b ~AiW V
LJ i E I ,W
a ~ AxA'w (V, V ') iff a = (b, b') for some b ~Aw V and b' ~A 'W V'

b ~~Aw x , s , return V iff b = .L or


b=return (x , s , a) for some c s.y ; V
f ~ lrr B x ,s, A{ . .. .i.u. ,...} iff, for each i E I , i'f ~hiW x , S, M ,
iE I - i W
f ~~ --+liw x , s , Ax.M iff, for all a E [A] w , ([A] ~) a ~Ax V implies
a' f ~hw x,s, M [V / x]

b ~hw x,s ,M iff b =..l or


x , s, M .lJ- x ' ,s' , T and b ~hw x', s' , T

Not e that for terminal T , b :::; ~w x, s, T iff b :::;kw x, s, T . We show that ,


for any datatyp e D , a f-'Dw V Iff a = [V] w , byinduction on D . Finally,
we show, by mutual induction on M and V , that
• for any computat ion w IA o, ... , A n - 1 f-c M : B , if w :::; x, s E S x and
--+
ai :::; ~b
, W i for i = 0, ... , n - 1 then [M] x sal :::;~x
-
x, s, M[Wdxi]

• for any value w IA o, . . . , A n- 1 f-v V : A , if w :::; x and ai :::;A.x W i for


--+ '
i = 0, ... ,n - 1 then [V] xal :::;Ax V[WdXi]'
o
Corollary 66 Let M be a closed ground ret urner in world ui . Then
w,s, M .J.l. w',s', r et ur n n iff [M]w s = return (w' , s' ,n) , and w,s, M
diverges iff [M]w s =.1.. Hence terms with the same denotation are
observationally equivalent. 0

It is also easy to show that provably equal terms have the sam e denota-
tion i.e. the model validates the CBPV equ ations.
We not e that this semant ics takes place entirely in predomains and
dom ains, in the sense of Def. 4.8, because we required in Sect. 6.4 that
the set of cell types N be countable. If N were un countabl e, t hen t he
countable base condit ion would be violated.

6.9 Related Models and Parametricity


In t he models of t his cha pte r, t he observational equivalences (6.2) and
(6.3) are not valid at ed (although (6.3) is valid ated when V and W have
distinct types) . By cont rast, the older models do valid ate these equiva-
lences , so it is immediat ely clear that t here are substanti al differences.
136 CALL-BY-PUSH- VALUE

For example, the Idealized Algol model of [Oles, 1982] interprets


conun-corresponding to! the CBPV type U conun of thunks of commands-
at w by Sw --+ Sw. Contrast this with our model which interprets U conun
at w by TIw':>-w(Sw' --+ L-w":>-wSW"). There are two differences between
these semantics, both a co~equence of the fact that in Idealized Al-
gol only ground values can be stored. (Indeed the cell storage model
of [Ghica, 1997] provides a semantics of comm similar to ours.) To un-
derstand these differences, suppose that V is a closed w-value of type
Uconun.
• Our model specifies the behaviour of V when forced in any future
world-store (hence the TI), and we have imposed no relationship be-
tween the behaviour in different worlds. In the Idealized Algol model,
by contrast, if V is forced at (w' , s') , its behaviour is determined by
the restriction of s' to a w-store. The extra cells will be unaffected,
because they cannot be stored in the cells of w . Thus the contravari-
ance of S (mentioned in Sect. 6.6.3) is essential to this model.
• Our model says that, when V is forced , new cells can be generated
(hence the L-) ' In the Idealized Algol model, any new cells can be
garbage-collected when the command is completed, because they will
not be stored anywhere. This feature is known as the stack discipline
of Idealized Algol.
It is because of these differences that , in the Idealized Algol model,
the naturality condition is required across all world-injections -this is
explained in [O'Hearn and Tennent , 1995].
Moggi's model [Moggi, 90] for CBV with ref 1 uses contravariance
of S in a similar way to the Idealized Algol models. But as the lan-
guage (called v-calculus in [Stark, 1994]) includes returners other than
ground returners (unlike Idealized Algol, where the only returners are
commands), there is no stack discipline. So the interpretation of T1
(again corresponding to Uconun in CBPV) at w is Sw --+ L-w':>-wSw'.
However , this summation is quotiented by an equivalence relati;n, and
this is how the observational equivalences of Sect. 6.3.4 are validated.
Such quotienting is easy when working with sets (as Moggi does) , but
problematic when working with cpos. For although it is possible to quo-
tient a cpo by an equivalence relation [Jung, 1990], we do not have the
simple characterization of elements that we have in the case of sets.

1 Although Id eali zed Algol is a C BN language, the possible world model of [Oles, 1982] is
essent ially a model of t hunks- t his is why this model do es not allow di rect int erpret at ion
of conditionals a t all types. Hence a type of this langu age is interpreted as a V typ e, and
deno tes a cova ria nt functor.
Possible World Model For Cell Generation 137

We can recover all of these models of storage by taking t he CBV model


for storage given in Sect. 6.6.4 and imposing a weak form of relational
parametricity [O'Hearn and Tennent, 1995J called "parametricity in ini-
tializations" . We will not describe t his restricted model here ; it does
not exhibit a simple CBPV decomposition in the way that the basic
model does. (This situation is analogous to t hat of the CBV model for
finite nondeterminism, discussed in Sect. 5.5.3.) Furthermore, as with
Moggi's model, it is not simple (although possible) to generalize from
sets to cpos, because of the quotienting required.
A rather different possible world model, whose relationship to ours we
have not invest igated, is Odersky's model for r ef 1 in a CB N language
[Odersky, 1994J.

6.10 Modelling Thunk Storage And Infinit ely


Deep Types
We now wish to adapt the model for cell generation + divergence
(Sect. 6.8.3) to treat t hu nk storage, so that 1>( C) can be any value type
rather than only a data type. The difficult part of our task is the se-
mantics of types, which shou ld be organized as follows.
• Sw is a cpo for each world w .
• [A] is a covariant functor from W to Cpo, for each value type A.
• [B] is a contravariant functor from W to Cpo", for each computation
type B.
Collectively, then, the semantics of types will be given by an object in
the category
B = Cpo'" W X [W , cpot altypes x [Wop, Cpo-lJcomptypes

These functors should satisfy the isomorphisms

S ~

X [1>(C)]
(C , l) E cells
[UB] ~
Us [B]
[L iEI Ai] ~
LiEI [Ai]
[A x A'] ~
[A] X [A']
[r efe] ~
$c
[F A] ~
Fs[A]
[TIiE1B i] ~
TIiEI[B i ]
[A -7 B] ~
[A] -7 [B]
138 CALL-BY-PUSH- VALUE

where we use the following terminology.


Definition 6.5 1 For X an object of [WoP, Cpo''] and S an object of
Cpo'" W , we write UsX for the object of [W, Cpo] given at w by
UITw':>-w(Sw' -+ Xw') and at ~ by the restriction.
'"
2 For X an object of [W, Cpo] and S an object of Cpo'" W , we write
FsX for the object of [W, Cpo"] given at w by F~W'?w(Sw' X Xw')
and at ~ by the inclusion.
3 For a cell type C EN, we write $c for the object of [W, Cpo] given
by $wc at wand by inclusions at ~, .
4 For {XA} AEN a family of objects in [W, Cpo] we write x
(0, I) E cells
for the object of Cpo'" W given at w by X Xc w .
(0,1) E cells w

5 We write ~, x, IT, -+ for the evident pointwise operations on covari-


ant and contravariant functors.
o
These isomorphisms collectively describe an isomorphism in B. How can
we construct this isomorphism? We apply Prop. 30 and Prop.32, which
tell us that
• Cpo'" W is sub-bilimit-compact in p'Cpo'" W- we call this category
S
• [W, Cpo] is sub-bilimit-compact in [W, Cpo] .-+ [W, pCpo]-we call
this category A
• [WOP , Cpo'] is bilimit-compact-we call this category B
Consequently B is sub-bilimit-compact in
c= S x Ava1types x Bcomptypes

We must therefore specify a locally continuous functor from CoP x C


to C; the semantics of types will then be given as the minimal invariant
of this functor. The functor is constructed straightforwardly using the
following analogue of Prop. 37.
Proposition 67 In the following, we write

• X for a morphism in A
• Y for a morphism in B
Possible World Model For Cell Generation 139

• S for a morphism in S
and we use the op era tions on st rict cont inuous and par ti al cont inuous
functions defined in P rop. 37.

• {XA} AEvaltypes t---+ X X A extends to a locally cont inuous fun c-


(A, I) E cells
tor from Avaltypes to S , when we set

X XA )W = X
(A, I) E cells (A,I) E cells w

• (8, X) t---+ UsX exte nds to a locally continuous fun ctor U from Sop x B
to A , when we set

• L i EI exte nds to a locally continuous functor from AI to A , when we


set

• x extends to a locally cont inuous fun ct or from A x A to A , whose


ope ration on morphisms is given by

(X xX')W =XwxX'W

• (8, X ) t---+ FsX extends to a locally cont inuous fun ctor F from S x A
to B, when we set

• Di EI exte nds to a locally cont inuous functor from B I to B, when we


set

OP
• -+ exte nds to a locally continuous fun ctor from A x B to B, when
we set
(A -+ Y )w = (Aw) -+ (Yw)

o
It is clear from Prop. 67 t hat t he isomorphisms above indeed define a
fun ct or from Cop x C to C, and we t hus obtain our sema ntics of typ es.
Havin g const ructed functors satisfying t hese isomorphisms , we define
140 CALL-BY-P USH-VALUE

op erations on semant ic stores and then define semant ics of terms just as
in Sect. 6.8.3 (where these isomorphisms ar e all identities).
Proposition 68 (Soundness/Adequacy) 1 Suppose M has type B
and w, s, M -U- w', s', T. Then [M]w[s] = ([B] ~, )([T]w'[s']).
2 Suppose w, s, M diverges. Then [M]w[s] = L
D

(1) is straightforward. To prove (2), we ad ap t the proof of Prop. 65(2) .


To show the existe nce of the required logical relation, we apply Pitts'
methods [Pit ts , 1996] (which work for any bilimit-compact category) to
the category C.
Corollary 69 For a closed ground w-returner M , there exists s' such
t hat w, s,M -U- w', s', r et ur n n iff there exists s' such that [M]w[s] =
return (w', s',n) , and w, s,M diverges iff [M]w[s] = L Hence terms
with the sam e denotation are observationally equivalent. D

Finally, we observe that everything we have done in this section works


if, in addit ion to gener al stora ge, we allow infinitely deep types.
Chapter 7

JUMP-WITH-ARGUMENT

7.1 Introduction
In Sect . 5.4.6, we presented a cont inuation semant ics for CBPV+ cont rol ,
together with printing. (We use printing as our leading exa mple of a non-
control effect in t his discussion, but ot hers would work as well.) We used
CBP V as t he seman tic metalanguage , and we gave not just one model,
but a whole family, parametrized by an A-set Ans. W hat we described
t here was , in effect, a translation

CBPV + cont rol CBPV + Ans


+ pr i nt + pr i nt

where Ans is a free computation ty pe identifier . Any A-set Ans in-


duces a deno tati onal semantics for CBPV + Ans + print (where we
interpret Ans by Ans) and so, via t his translation , a denotational se-
mantic s for CBPV + cont rol + print. T he t ranslation is called t he
stack-passing style (StkPS) transform, becaus e every computation is re-
garded as t aking its stack as a par ameter . (In t he CBV setting, it is
called the continuation-passing style (CPS) transform because all stacks
are cont inuat ions.)
Bu t a cont inuat ion semant ics is far more t ha n just a denotati onal
model. As St eele explained in t he CBV setting [Steele, 1978], it pro-
vid es a ju mping implem entation. This is becau se t he ran ge of t he StkPS
transform is not t he whole of CBP V+Ans , bu t a very spec ial frag ment
which we call Jump- With-Argument (J WA). This fragment , which is
very similar to Steele's interm edi ate language and vari ous like calculi
[Appel, 1991; Appel a nd J im , 1989; Danv y, 1992; Sabry an d Felleisen ,
1993; T hielecke, 1997a], is worth separating out from CBPV+ Ans and
study ing indep endently, because it can be regard ed as a language of
j ump instructions. In Steele's words:

141
P B Levy, Call-By-Push-Value
© Springer Science+Business Media Dordrecht 2003
142 CALL-BY-PUSH- VALUE

Continuation-passing style, while apparently applicative in nature, admits


a peculiarly imperative interpretation[. . . ] As a result , it is easily converted
to an imperative machine language. [Steele , 1978]

To summarize, the StkPS transform goes from CBPV + control +


print to a jumping language JWA + print , which is a fragment of
CBPV + Ans + print.

CBPV + control StkPS JWA CBPV + Ans


+print transfor~ +print +print

The StkPS transform translates force V and return V into jump


commands. It therefore makes apparent the intuitive point that we made
in Sect. 1.5.3: that force and return are the only two instructions
that cause execution to move to elsewhere in the program. This shows
once again the advantage of working with CBPV rather than CBV and
CBN, which do not make the flow of control so explicit.
In addition to the jumping operational semantics for JWA, we also
describe a more conventional operational semantics, the C-machine, and
explain their agreement. We define observational equivalence and an
equational theory for JWA-as usual, this requires complex values.
We digress in Sect. 7.7 to explain how JWA can be regarded as a
type theory for classical logic. This is based on the classic treatments
of [Friedman, 1978; Griffin, 1990; Lafont et al., 1993]. But we urge the
reader, except during Sect. 7.7, to ignore logical issues-in particular,
ignore the fact that the symbol -, for continuation types is the same as
the traditional symbol for logical negation. Furthermore, it would be
hard to argue that the logical reading by itself provides a motivation for
JWA.
Finally, we see in Sect. 7.8 that CBPV+control is equivalent to JWA,
along the StkPS transform. (This is very similar to the "equational
correspondence" result of [Sabry and Felleisen, 1993].) Consequently
models for CBPV+control are essentially the same as models for JWA -
a useful fact, because JWA is so much simpler.

7.2 The Language


JWA is an extension of Thielecke's "CPS calculus" [Thielecke, 1997a].
Unlike Thielecke's language, but like the untyped languages of [Danvy,
1992; Sabry and Felleisen, 1993; Steele, 1978], it includes values and
abstraction.
The types of JWA are given by

(7.1)
Jump-With-Argument 143

where each set I is finite (or countable, for infini tely wide JWA ). A valu e
of ty pe -,A is an "A-accepting jump-point"-intuit ively, a point that we
jump to taking an argument of ty pe A. For exa mple, a BASIC line num-
ber would have ty pe -,1 , because the argume nt is trivial. Although we
have followed the established usage of -, for jump-point types, we con-
sider it to be a confusing usage because -, is not exactly logical negation ,
as we explain in Sect . 7.7. There are two judgements
r f-v V: A r f-n M
called resp ectively values and n onreturning commands (in the sens e of
Sect. 2.9.2-we will sometimes omit the word "nonret urn ing" ). The
terms of JWA are given in Fig. 7.1.
The embedding of JWA in CBPV+Ans (with printing, if desired) is
given in Fig. 7.1. We thus obtain, for each A-set Ans, denotational
semantics for JWA+print . By using the empty A-set for Ans, we can
prove
Proposition 70 There is no closed nonreturning command in JWA. 0
Because of this situation , we always consider ope rationa l semant ics for
non-closed nonreturning comma nds; execution te rminates when we at-
te mpt to jump to or pat tern-match a free identifier.
In t he abse nce of effects , JWA can be seen as a fragment of t he
x L:TI ---+-calculus (presente d in Fig. 3.8), and t his has been the usual
viewpo int in t he litera ture. However , it is not valid in t he presen ce of
effects .
The following will be of great import ance to our informal discussion
of pointer games in Cha p . 8.
Proposition 71 Any closed valu e in JWA consists of several tags and
several jump-points. 0

7.3 Jumping
7.3.1 Intuitive Reading of Jump- With-Argument
We said in Sect. 7.2 that an A-accepting jump-point (a value of type
-,A) is a point that we jump to taking an argument of type A . We
explain t he constructs for -, in a similar way.
• V /' W is the comma nd "j ump to t he point W taking argument V " .
• 'Yx .M is a point. When we jump to it taking argument V, we bind x
to V and then obey t he command M.
T he easiest way to gras p t his will be to see t he execution of an example
program. Our explanation of jumping is informal; its aim is to convey
t he jumping intuit ions of JWA.
144 CALL-BY-P USH-VAL UE

r f-v V : A r ,x : A f-n M
r ,x : A , r ' f-v X : A r l-" let V be x . M

r f-v V: L iE/A i ... r ,x : Ai f-n Mi . . . i E/

r l-" pm V as {... , (i, x) .Mi , ... }

r f-v V : A r f-v V' : A' r f-v V : A x A'r, x : A , y: A' f-n M


r f-v (V, V') : A x A' r l-" pm V as (x , y) .M

r ,x: A f-n M r f-v V : A r f-v W : -,A


r f-v ,x.M : -,A r f-n V ? W

For printing, we add the const ruct


r f-n print c. M

To see Jump-With-Argument as a fragment of CBPV +Ans, regard

-,A as U(A -+ Ans)


r f-n M as r f-c M: Ans
,x.M as thunk Ax.M
V?W as V 'force W

Figure 7.1. Terms of J ump-With- Argumont , and its embe dding into CBP V+ Ans

7.3.2 Graphical Syntax For JWA


The term synt ax (m ore acc urately, the abs t ract syntax) for JWA is
rather inconvenient for jumping around. We therefor e use a graphical
flowchart-like syntax, illustrated in Fig. 7.2, wh er e

• since , represen t s a point , it is written.

• each instruction is enclosed in a rect angle;

• binding occurren ces of iden tifiers and patterns are pl aced on edge s
(enclosed in a rounded rectangle).
Jump - With-Argum ent 145
We give the name jumpabout to this kind of tree of rectangles, edges
and points. (We will not give a precise definition, as our explanation of
jumping is informal.)

7.3.3 Execution
We will illustrate execut ion using the command y : nat f-n M whe re
M is the last example in Fig. 7.2. Here is t he graphical syntax; we have
numbered each point and each rectangle for ease of reference.

This jumpabout is called the code . As we execute it , we form anot her


jumpabout called the trace. We call a point in the code jumpabout a
code point , and a point in the trace a trace point ; similarly for rectangles.
During execution, the cod e st ays fixed but the trace grows. The basic
cycle of execution is
• copy the cur rent ins truction from the cod e to the trace
• obe y the cur rent instruction in the t race.
We begin at the top ; then we follow the sequence of instructions down
the code, except when we jump.
cycle 0 copy instruction We copy the instruction let • be from
code rect angle 0, giving
let . 0 [0] be I...

Notice that we number each trace point, and indicate in squar e


brackets the code point that it was copied from-the latter is
called the teacher . Thus code point 0 is the teacher of trace
point O. To reduce clutter , we omit t he numbers and teachers of
t race rect angles.
We write ~ for "where we are now" .
obey instruction Now we must obey this instruction, by binding
t he valu e ptO to x giving
146 CA LL- BY-PU5H- VAL UE

Term Syn tax Gr aphical Syntax

print "hello ". print "goodbye" . 3 /" y

inl y. print "he l l o ". 3 /" Y


pm z as {
inr y. diverge

pm z as (x, y) . print "hello" . 3 /" y

let 3 be x. print "he l l o". x /" y

')'x .(pr i nt "hello". x /" y)

let ')'x.(pr i nt "he llo ". x /" y) be w. (3 /" w)

Figure 7.2. Examples of Graphica l Sy ntax for J WA


Jump- With-Argument 147
cycle 1 copy instruction We copy the instruction 3 )'I w from cod e
rectangle 3 to the trace, giving

Notice that we have replaced w with its binding, point O. We find


this binding by looking up the branch of the trace.
obey instruction The instruction tells us to jump to point 0 (i.e.
trace point 0) taking 3 as an argument. We obey it by jumping
to trace point 0 and binding x to 3, giving

cycle 2 copy instruction We copy the next instruction print "hello"


from code rectangle 1 to the trace, giving

obey instruction Vje obey this by just printing "h e llo" . No bind-
ing is made, so we ar e ready for the next instruction:

cycle 3 copy instruction We copy the next instruction x )'I y from


code rectangle 2 to the trace, giving

Notice that we have replaced x with its binding 3. We find this


binding by look ing up the branch of the trace.
148 CA LL-BY-PUSH- VALUE

obey instruction T his instruction te lls us to j ump to y taking 3.


Bu t y is free , so execution te rminates:

Notice t hat t he fun ction taking t race points and trace rectan gles to
t heir teachers describes a j ump ab ou t homomorphism called t he teacher
homom orphism from t he trace to the code. As t he trace grows during
execut ion, the teacher homomorphism grows with it.
T his example progr am is very simplist ic. More int eresting sit uations
arise when we jump several times to t he same trace po int. Each t ime,
a new branch of t he t race comes into existence, and so (un like in our
example) t here can be many t race points with t he same teacher. An
example is Fig. 7.3, wh ich t he reader is strongly encouraged to execute.

7.4 The StkPS Transform


7.4.1 StkPS Transform As Jumping
Implementation
T he St kPS transform from CB P V+ cont rol to JWA is given in Fig. 7.4.
By composing it with t he embedding in F ig. 7.1, we recover t he cont in-
uation semantics given in Sect. 5.4.6.
As we have describ ed (if only informally) a j umping operationa l se-
mantics for J WA, we obtain from t he St kPS transform a jumping im-
plementation of CBPV+control. Noti ce t he following.
• As dep icted in Fig. 5.7, there are 2 kinds of values t hat are t rans-
lated as jump-point s: thunks and cont inuations . T his means t hat, in
CBPV, thunks and continuations are point s t hat we can jump t o.
• T here are 2 comp utations t ha t are translated as jump s: force V
(which is a jump to t he t hunk V ) and return V (which is a j um p
to t he cur rent cont inuation) . T his makes precise t he int uiti on of
Sect . 1.5.3.
• The t ransform of a computation describes its behaviour in t he CK-
machine . For insta nce, the computation Ax.M first pattern-matches
its stack as V :: K , t hen binds x to V , t hen performs M wit h stack
K. T his is exactly described by the transform of Ax.M .
Jump- With-Argument 149

(a) the code-term syntax


i : -,bool f-n let ')'x.(
pm x as (u, v) .
let ')'w.(v ? i) be w.
pm u as {inl y.(w ? y), inr y.(O ? y)}
) be f . ((inl ')'z.((inr z , false) ? f) , true) ? f)
"-"7 * true? i

(b) the code-graphical syntax

(c) the trace

x I-t (inl ptl , true )

• 1(1) , true ) / ' ptO

Figure 7.3. Example Program With Repeated Jumps-Please Try This

7.4.2 Related Transforms


The various CPS transforms that appear in the literature, listed and
discussed in [Thielecke, 1997a], can all be recovered from the StkPS
150 CALL-BY-PUSH- VALUE

A B
UB --,B FA --,A
L: iEI A i L: iEI A i IliEIB i L: iEI B i
A xA' A X A' A --tB A xB
stk B B nrcomm 1

A o, ... , A n - l f-VV : B
x x
(i , V) (i ,V)
(V, V ') (V , V ')
thunk M , k .M
[.] to x. M :: K , x .(M[K /k])
i ·:: K (i ,K)
V ·: :K (V ,K)
A o, ... ,An - 1 f-c M : B A o, ... ,An - l , k : B f-n M
let V be x. M let V be x. M
pm V as {... , (i, x ).Mi" " } pm V as {. . . , (i , x ).M i , . . . }
pm V as (x, y ).M pm V as (x, y ).M
return V V / k
M to x. N let ,x.N be k . M
A{.. . , i . M i , . . . } pm k as {... , (i, k) .Mi" "}
i' M let (i , k ) be k. M
Ax .M pm k as (x,k) .M
V 'M let (V , k ) be k. M
force V k/ V
letstk x. M let k be x. M
changestk K . M let K be k . M
print c. M print c. M

Figure 7.4. T he St kPS transform from CBPV+contro! to JWA , wit h printing

transform, because in each case the sou rce language is a fragment of


CBPV+control.

• Primary among these transforms is t he CBV CPS transform [Duba


et al. , 1991; Plotkin , 1976]. This is recovered from the St kP S trans-
form along the embedding of CBV into CBPV. The CBV control
Jump- With-Argument 151

operators (as in ML) are translated into CBPV as follows:

cont A as stk FA
letcc x. M as letstk x. M
throw M N as M to x. N to y. (changestk x. return y)

• The "CBN CPS transform" [Plotkin, 1976] is, in our terminology of


Sect. 1.7.3, not CBN but lazy. Thus, as explained in [Hatcliff and
Danvy, 1997], it is recovered from the CBV CPS transform via the
thunking transform which we present in Sect. A.5. Many of the other
CPS transforms listed in [Thielecke, 1997a] are likewise fragments of
CBV .
• The "CBN CPS transform" of [Hofmann and Streicher, 1997] is in
our terminology StkPS rather than CPS, but it is genuinely CBN and
is recovered from our StkPS transform via the embedding of CBN in
CBPV.
This provides yet another illustration of the unifying power of working
with CBPV-it provides the source language for the StkPS transform
from which all the others are obtained.
Furthermore, the target language JWA of the StkPS transform is also
CBPV, in the sense that it is a fragment of CBPV +Ans (as we explained
in Fig. 7.1). Admittedly, the transitions of Fig. 7.5 can be seen as CBN
reductions or as CBV reductions-this is essentially the indifference re-
sult of [Plotkin, 1976]. But for denotationaljequational purposes, we
cannot regard JWA as embedded in CBN, because this embedding does
not preserve the 1]-law for sum types. Regarding JWA as embedded in
CBV is also somewhat problematic: .....,A is then regarded as

A -+CBV Ans = U(A -+ FAns)

Thus Ans in Fig. 7.1 has been replaced by FAns , and we have lost gen-
erality. In the case of printing, for example, the embedding in Fig. 7.1
provides us with a JWA semantics for any A-set, whereas the embedding
in CBV allows only a free A-set.
In summary: we have benefited from ensuring that both the source
language and the target language of the StkPS transform are CBPV.

7.5 C-Machine
7.5.1 C- Machine for Effect-Free JWA
Whilst the jumping operational semantics for JWA is intuitive, it is
useful to have also a more conventional operational semantics based on
152 CA LL-BY-PUSH- VALUE

Transitions

r let V be x.M
r M [V/ x]

r pm (i , V) as {... , (i , x) .Mi , .. . }
r Mi [V/ x]

r pm (V, V ') as (x , y).M


r M [V/ x , V ' /y]

r V / , x .M
r M[V/x]

Terminal Configurations

I', z : -,A , r' V / z


r ,z : I: i EIAi , r' pm z as {... , (i , x). M i , ... }
r , z: A x A',r' pm z as (x , y).M

Figure 7.5. C-Machine for Jump-With-Argument

abs t ract syntax. The C-ma chin e is given in Fig. 7.5. It is similar to the
CK-machine, except that there is no need for a stack. Recalling from
Sect. 7.2 t hat we work with non-closed nonreturning commands, we fix a
context I' , and define a r -configuration to b e a nonreturning command
r f-n M .
Proposition 72 (determinism) (cf. Prop. 46) For every r -configuration
M , precisely one of t he following holds.
1 M is not t erminal , and M "", N for a unique r -configuration N.
2 M is terminal, and t here does not exist N such that M "'" N.
o
Definition 7.1 (cf. Prop. 2.4) We define the relat ion "",* on configura-
tions inductively:
M ' "",*N
- - - ( M "",M')
M "",*N
o
Jump- With-Argum ent 153

Proposition 73 (cf. 47) For every I' configur ation M there is a unique
terminal I'-configur at ion N such that M "Y'-t * N , and there is no infini te
sequence of transitions fro m M, 0

Proof (in the style of [Tait , 1967]) We fix f. We say that a f-configuration
M with the properties described in Prop. 47 is reducible. Thus our aim
is to prove that every f- configuration is reducible.
For each type A we define a set red'A of reducible values I' I- v V : A
by induction on types.
• I' I- v V : -,A is reducible iff V is eit her a free identifier or ,x.M where
for all V E red'A , M[V/xJ is reducible.
• I' I-v V : 2:iEIA i is reducible iff V is either a free identifi er or (i , W)
where W E red'A..

• I' I- V V: A x A' is reducible iff V is eit her a free identifier or (W, W')
where W E red'A and W' E redA,.
By mutual induction on M and V , we prove the following.
• For any non returning command I' , A o, ... , A n - 1I- n M , and any Wo E
---+
red'Ao" ' " Wn - 1 E redAn_I ' the f -configuration M[WdxiJ is reducible.
• For any value I' , A o, . . . , A n - 1 I-v V : B , and W o E red'A o"'" W n - 1 E
---+
red'An_l ' the valu e V[WdXiJ is reducible.
o

7.5.2 Adapting the C-Machine for print


In Fig . 7.5 a transition has the form

M M' (7.2)
Len we add print to the lan guage, we want a transition to have the form

M m M'

some m E A*. We therefore repl ace each t ransit ion (7.2) in Fig. 7.5 by

M 1111
M'

l we add the t ransit ion

print c. M c M
154 CA LL-B Y- P USH- VALUE

We replace Def. 7.1 by the following.


Definition 7.2 We define the relation ~* , whose form is M ~* m , M'
ind uct ively:
M ' ~* n ,N
- -- - - - (M ~ m ,M')
M ~* I ,M M ~* m * n ,N
D

It is easy to prove analogues of Prop. 72-73 .

Proposition 74 (soundness) If M ~* m, T then , for any p E [r] ,

[M] p = m * ([T ]p)


D

Corollary 75 Suppose Ans has two elements a, b with the property that

m * a I- m' *a for m I- m' E A *


m * a I- m' *b for m ,m' E A*

(This property is satisfied by the free A-set on a set of size ~ 2.) For a
countable set N and element n , write I N,n for t he function from N to
Ans that takes n to a and everyt hing else to b.
Then for any nonreturning command k : .l:iEN1 f-n M , we have
M ~ * m , n / k iff [M](k t---+ IN,n) = m * a. Hence te rms with the same
denotation are observationally equivalent . D

7.5.3 Relating Operational Semantics


We now have 3 op erational semantics, each of which can be extended
for print :
1 the CK-machine for CBPV+control,
2 the C-machine for JWA ,
3 the jumping machine for JWA (wh ich we have described only infor-
mally) .
The StkPS transform exactly preserves machine progress, from (1) to
(2):
Proposition 76 Let M , K be a f -configuration of t he CK-machine for
CBPV+ control. Then M[K /k] is a f -configura tion of the C-machine.
Furthermore:
Jump- With-Argument 155

• M , K is te rm inal iff M[K / k] is te rminal.


• If M,K ..--. N ,L, t hen M [K/ k] ..--. N [L/k].
D

This ena bles us to deduce t he terminat ion of t he CK-machine (Prop. 47


and t he weaker Prop. 12) from t he termination of t he C-mac hine for
JWA (Prop. 73).
Likewise, t he relationsh ip between the (2) and (3) is exac t : one transi-
tion of t he C-machine corresponds to one cycle of t he jumping machine.
(We do not prove this here.) For example, t he comp utat ion in Sect . 7.3.3
rewrites in 3 transitions to 3 /' y, printing hello in the last t ransit ion .
These transit ions corresp ond to cycle 0, cycle 1 and cycle 2 in the jump-
ing execut ion.

7.5.4 Observational Equivalence


Definition 7.3 A ground con tex t is a nonreturning comma nd

with one or mor e occurrences of a hole which may be a nonreturning


command or a value. D

Definition 7.4 Let I' 1-" M and I' 1-" N be nonr eturning comma nds .
We say t hat M ~ N when for any ground conte xt C

C[M] ..--. * n /' k iff C[N] ..--. * n /' k


Simi larly for values. D

We can easily adapt Def. 7.4 to different computational effects, e.g.


printing.

7.6 Equations
7.6.1 Equational Theory
We present ed the syntax for JWA in F ig. 7.1. But before we formulate
t he equa t ional t heory, we need , as usu al, to add complex values to JWA .
This is done j ust as for CBP V, in Fig. 7.6. As in Sect . 3.2, we exclude
t hese values when considering ope rationa l semantics, but include t hem
ot herwise. We define the equational t heor y in Fig. 7.7. As with CBPV,
we have
Proposition 77 1 Any comp utation is provab ly equal to a computa-
tion without complex value constructs.
156 CALL-BY-PUSH- VALUE

r f-v V : A r , x : A f-v W :B
r f-v let V be x. W : B

r f-v V: L:iEIAi ... r ,x : Ai f-v Wi : B . .. iE I


r f-v pm V as { ... , (i, x). Wi, ...} : B

r f-v V : A x A' r , x: A , y : A' f-v W : B


r f-v pm Vas (x ,y).W: B

Figu re 7.6. Complex Valu es For JWA

2 Any closed valu e is provably equal to a closed value without complex


value constructs.
o
The reversible derivations of JWA are presented in Fig. 7.8.

,B- Iaw s
let V be x. Q Q[V/x]
pm (z, V) as { . . . , (i, X) .Qi, " '} Qz[V/x]
pm (V, V') as (x, y) .Q Q[V/x, V' /y]
V / "(x.M M[V/x]

77- 1aw s
Q[V/z] pm Vas { ... , (i, x). 1<Q[(i,x)/z], ... }
Q[V/z] pm V as (x, y). xYQ[(x, y)/z]
V "(x.(x .> XV)

Figure 7.7. JWA equa t ions, using convent ions of Sect . 1.4.2

7.6.2 Example Isomorphisms


In JWA we can coalesce several continuations into one, using

(7.3)

To make this precise, we need to define syntacti c isomorphism.


Definition 7.5 An isomorphism from A to B is a pair of valu es x :
A f-V V : Band y : B f- W : A su ch that V[W/x] = y and W[V/y] = x
are provable. 0
Jump - With-Argument 157

Ru les for x

r f-v A r f-v AI
Rules for L r f-v A x AI

r ,Ai f-v B .. . iE/ r ,A,AI f-VB


r ,L iE/Ai f-v B r ,A x AI f-v B

... r , A i f-n .. . i E/ r , A, AI f-n


r ,L iE/Ai f-n r ,A x AI f-n

Rule for -,

r, A f-n
r f-v -,A

Figure 7.8. Reversible Der ivations For JWA

The isomorphism 7.3 is then easily constructed.


Proposition 78 Every JWA type is equivalent to one in type canonical
form , meaning a type in t he following class:

A ..= L iE/-, A i
o
Explicitly, a type canonical form can be written

(7.4)

7.7 JWA As A Type Theory For Classical Logic


We said in Sect. 7.2 that the type const ructor -, in JWA is not exactly
the same as logical negation. This is because (for example) there does
not exist a value -,-,0 f-v V : 0, even t hough -,-,0 f- 0 is provable in both
int uitionisti c and class ical logic.
But although the JWA value judgement f-v is not related to logic, t he
JWA nonreturning com m and j udgement f-n is rela ted to logic. This is
an example of the phenomenon described in Sect. 2.10: many results
apply only to computations, and the role of values is merely auxiliary.
We now explore this relationship.
158 CALL-BY-PUSH- VALUE

Definition 7.6 • By intuitionistic propositional logic we mean the


type theory x LIT -e-calculus defined in Fig. 3.8, omitting the terms.
Thus a sequent has the form r I- A.

• By classical propositional logic we mean Gentzen 's system LK (see


e.g. [Girard et al., 1988]), where we write L for disjunction and x
for conjunction. Thus a sequent has the form r I- .6., where both r
and .6. are "contexts" i.e. finite sequences of propositions. We say
that r I- .6. and r' I- .6.' ar e provably equivalent when

I- (/\ r :::} V.6.) {::? ( / \ r' :::} V.6.')


is provable.
D

Some remarks:
• Any other formulation of classical logic, e.g. Hilbert 's, or that of the
Sheffer stroke, would be just as acceptable for our purposes.

• According to Def. 7.6, ---, is included among the primitive connectives


of classical logic, but not among those of intuitionistic logic.

• We have provided an equality relation between intuitionistic proofs


(the equational theory of Sect. 3.8) , and this equates any two proofs
of rI-o (easy exercise, whose categorical analogue is Prop. 4(3)) .

• By contrast , we do not provide any equality relation between classi cal


proofs.
We can now state the key result , central to much work relating control
effects and continuations to logic [Friedman, 1978; Griffin, 1990; Hof-
mann and Streicher, 1997; Lafont et al. , 1993; Murthy, 1990].
Proposition 79 1 Any sequent of classical logic is provably equivalent
to a sequent of the form I' 1-, where I' is a JWA context.
2 If r is a JWA context , then I' I- is provable in classical logic iff there is
a nonreturning command I' I-n M in effect-fr ee JWA (with or without
complex values, it makes no difference by Prop. 77).
D

We stress that this is a result about provability, not about proofs, and
we do not regard as canonical any particular translation from LK into
JWA. After all , we not would regard as canonical any particular trans-
lation from LK to Hilbert 's system. All Prop. 79 tells us is that such
Jump- With-Argument 159

translations exist, which is all that is needed for JWA to be a system of


classical logic.
Proof 1 is straightforward. 2 is a consequence of the following stronger
result. Let r be a context in Jump-With-Argument. Then the following
are equivalent. 1 .

1 r f- is provab le in classical propositional logic.

2 There exists a nonreturning command r f-n M in effect-free JWA .

3 r[( - --+ Ans)/.] f- Ans is provable in intuitionisti c proposit iona l logic


extended with a proposit ion identifier Ans.

4 r[(- --+ 0)/. ] f- 0 is provable in intuitionistic propositional logic.

This is proved as follows.


(2) =}(3) T his is given by the composite t ransform
trivialization
JWA ~ CBPV+ Ans • x E D --+-calculus+Ans

which takes • to - --+ Ans and takes a nonreturning command to a


term of type Ans.

(3) =}(4) We substitute 0 for Ans.


(4) =} (1) T his is because

• intuit ionist ic provability imp lies classical provability;


• .A and A --+ 0 ar e equivalent in classical logic.
(1) =}(2) We define a transform (again, t his is j ust one choice and it is
not canonical) from propositions to J WA types as follows:

A A
.A .A
E iEIAi E iE/Ai
A x A' Ax A'
D iE/ Ai ·EiE/ · Ai
A--+B . (A x .B)

lThere is a rather fort uitous result that any (finit ely wide) pr oposit ion a l formul a of t he form
-, A is classica lly valid iff it is int uitionistically vali d . On e mi ght t hink t hat t he eq uivalence
bet ween (1) and (4) is no mo re than a special case of t his fact. Bu t t hat is not so, becau se
our proof extends to t he infinit ely wide set ting, a nd ca n easi ly be exte nde d to pr ed icat e logic.
160 CALL-BY-P USH-VALUE

We then show t hat if A o, . . . , A m - l f- B o, . . . , B n - l is provable, then


there is a nonret urning command A o, ... , A m - l , -,B o, ... , -,Bn - l f-n
M in effect- free JWA . The required result is an immediate conse-
quence, because the transform =leaves JWA typ es unchanged .

o
We ar gue that , in light of Prop . 79, JWA can be viewed as a typ e
theory for classical logic, provided we regard valu es (which are not log-
ically significant) as merely auxiliary. Whereas some ot her proposed
type theories such as AJL-calculus [Ong , 1996; Parigot, 1992J have to be
arbit rarily designated call-by-value or call-by-na me, JWA does not have
this problem.

7.8 The StkPS Transform Is An Equivalence


7.8.1 The Main Result

programs CK-machine equational theory

CBPV ~ CBPV

\
!
+ com plex valu es
conse rvative

I
CBPV ~ CBPV
+ stacks + stacks
+OOffiPj" ",Uffi /,t,m
CBPV - CB PV ~ CBPV
+ control + control + control
+ stacks + stacks
+ com plex values (incl. -ignor ed )

StkPS Transform equivalence

JWA JWA

.!
---------------~

!(;oIlser:v<t~i.ve.
+ complex valu es

CBPV + Ans -----------~ CBPV + Ans


+ com plex valu es

Figure 7.9. T he St kP S t ransform between vari ous lan gu ages


Jump- With-Argument 161

In Fig. 7.4 we presented t he St kP S transform from CBPV+cont rol


to JWA. In t his sect ion, we show t hat it is an equ ivalence, so models of
CBPV+control and models of JWA are essent ially the same t hing. How-
ever , JWA is much simpler and more elegant. We mention again t hat this
material, like all of our material involving equational theory an d com-
plex values, is not presently applicab le to infinitely deep CBPV/JWA,
alt hough it is applicable to infinitely wide CBPV/ JWA.
T he sense in which the St kPS transform is an equivalence is t he
following-a typed variant of the "equational correspondence" ap proach
of [Sabry and Felleisen, 1993]:
Proposition 80 1 Every J WA type A is isomo rphic to B for some
value type B.
2 Eve ry JWA type A is isomorphic to B for some computatio n typ e B .
3 For every context r and value ty pe A in CBPV+control, t he StkPS
transform defines a bijection from the provable-equality classes of
values r f-v V : A to t he provable-equality classes of values r f-v W :
A.
4 For every context r and computation type B in CBPV+control, the
StkPS transform defines a bijection from the provable-equality classes
of computations r f-c M : B to t he provable-equality classes of non-
returning commands r,k : B f-n N .
(3)-(4) can be extended to values and computations wit h holes i.e.
contexts. D

For P rop. 80 to ma ke sense , we will have to give an equational t heory


for CBPV+control. We do this in Sect. 7.8.3. We t hen prove P rop. 80
in Sect . 7.8.6.
Using Prop. 76, we ded uce
Corollary 81 T he StkPS transform is fully abstract. D

7.8.2 Complex Values


As depicted in Fig. 7.9, we want to contrive an equational t heory
for CBPV+control (including the stack constructs of Fig. 5.4) t hat will
make Prop . 80 true. As usual, we have to add comp lex values to get
an equational t heory with the desired properties, and the complex value
constructs are shown in Fig . 7.10. Except for the last one (·i gnor e d,
which we explain presently) these constructs all correspond to those in
Fig. 3.5.
In Sect . 2.9.2 we argued that there is essentially one stack from FO ,
called ignored. We defined ignored there in terms of nil. Since nil
162 CALL-BY-PUSH- VALUE

r f-v V : A r ,x : A f-v W : B
r f-v let V be x. W : B

r f-v V : I:i EIAi ... r ,x : Ai f-v Wi : B ... iEJ


r f-v pm V as {... , (i, x). Wi , ... } : B

r f-v V : A X A ' r, x: A , y : A' f-v W : B


r f-v pm Vas (x,y).W: B

r ,n: stk II f-v V : C r f-v L: stk II


r f-v V ·where n is L: C

r, n : stk lli f-v Vi : C .. . iEJ r f-v L : stk TIiE1lli


r f-v {... ,Vi ·where i-t: n, . . .} is L : C
r , x : A , n : stk II f-v V : C r f-v L : stk (A -+ ll)
r f-v V -vhar e x -i: n is L : C

r f-v ·ignored : stk FO

Figure 7.10. Complex Values For CBPV+Control

is a free identifier in the control setting, ignored is not closed. But we


need a closed value of type stk FO to make Prop. 80(3) true, because
stk FO denotes -,0 ~ 1. We therefore introduce a constant ·ignored as
shown in Fig. 7.10.

7.8.3 Equational Theory For CBPV -l-Control


The equational theory for CBPV+control consists of the usual equa-
tions of Fig. 3.3, together with those of Fig. 7.11 (using the conventions
of Sect. 1.4.2) . Notice that these equat ions are ad hoc and inelegant,
by contrast with the simplicity of the JWA equational theory, to which
they will be shown equivalent. The equations for print and diverge
are of course effect-sp ecific, but there would be a similar equation for
other effects.
Looking at Fig. 7.9, we see that there are 2 arrows into this equational
theory and 1 arrow out. There are thus 3 tasks we must perform for this
theory:
Jump- Wit h-Argum ent 163

,a- la w s
V ·Yhe r e n is L V[L/ n]
{. . . ,11; ·Yhe r e i ·:: n , . . .} is t· :: L 11; [L/ n]
V ·Yh e r e x·:: n is W .:: L V [W / x,L/ n]
changestk ([.] to x. N .:: K) . return V changestk K . N [V/ x]
changestk (t ·:: K ). A{ . . . ,i.Mi , .. . } changestk K. M ;
changestk (V ·:: K ). AX. M changestk K . M[V/ x]
changestk K . letstk x . M changestk K. M[K / x]
changestk K . changestk L . M changestk L . M

1/-laws
V [L/ z] { . . . , "V[i .:: n/z] ·Yhe r e i ·:: n , . .. } is L
V [L / z] =V [x -r: n/z] 'Yhere x c : n is L
changestk L. M [K / z] changestk K . A{ . . . , i. l e t s t k Y.
changestk L . VM[i -t: viz]' . .. }
changestk L. M [K / z] changestk K . Ax.letstk Y.
changestk L . XVM [x -r: viz]
K [.J to x . (ch ange s t k K . return x)
-i : ignored
K ·ignored
M letstk x. changestk x. "M
M changestk . ignored. M

sequencing law
changestk K. M to x . N = M to x . changestk "K, N

print law
changestk K. print c. M = print c. changestk K. M
diverge law
changestk K . diverge = diverge

Figure 7.11. Eq uational T heory For CBPV+Control

• to re prese nt in it t he equat iona l t heory for CBP V+ stacks (Sect. 7.8.4)


• to show t hat the embedding in it of CBPV+ control is computation-
un affecting (Sect. 7.8.5)
• to describe t he St kP S t ransform from it into t he JWA equationa l
t heory, and show t hat t his t ransform is an equivalence (Sect. 7.8.6).

7.8.4 Representing CBPV -l-Stacks In


CBPV+Control
We extend Fi g. 7.4 to treat complex stacks in Fig. 7.12.

Proposition 82 The embedding of CBPV+ stacks in CBP V+ cont rol,


shown in Fi g. 7.12, has the following properti es.
164 CA LL-BY-PUSH- VALUE

CBP V CBPV+ cont rol


r ,nil : stk C f-V K : s t k B
[.J to x. N :: K [.J to x. n>lN -t: K
i :: K i·: : K
V :: K nilv .:: K
K whe r e nil i s L n> l K .wh e r e n i l is L
{ . . . .K, where i :: n il , . . .} i s L {.. .. r-«, ·whe r e i·:: n il , . .. } i s L
K whe r e x :: nil i s L -v« -vhare x -r: nil is L

Figure 7.12. Representing f-k

1 It preserves substitution.
2 Dismantling is represented as follows. If r f-c M : B and riB f-k K :
G then
M . K = l et s t k nil. changestk K . M

3 Concatenation is represented as follows. If fiB f-k K : G and fiGf-k


L: D then
K * L = K[Ljni l]
4 The embe dding preserves provable equality.
o

7 .8 .5 Stacks and Complex Values Are


Computation- U naffecting
We took CBPV with the control operators letstkjchangestk, and
we added first the stacks of Fig. 5.4 (to typecheck the CK-machine) and
then the complex values of Fig . 7.10 (to formulate an equational theory) .
But these addit ions did not generate any new computations, as we now
see. The statement and the proof follow the same lines as Prop. 25(1),
but there is no result about closed values corresponding to Prop. 25(2)

Proposition 83 There is an effective procedure that, given a computa-


tion r f-c M : B , poss ibly containing stacks and complex values (includ-
ing ·ignored), returns a computation r f-c M : B without these things ,
su ch that M = M is provable. 0

Proof We will define one such procedure, and simultaneous ly, for each
value r f-v V : A , possibly containing complex valu es, and each complex-
value-free computation r , v : A f-C N : B , we will define a complex-
value-free computation r f-c N[Vjj v] : B su ch that N[Vjjv] = N [Vjv] is
provable.
Jump - With-Argument 165

By mutual induction on M and V , we define M and N [V jj v] in


Fig. 7.13 and we prove the equations

M=M
N[Vjjv] N[Vjv]

v N [V#v]
x N [x/ v]
let W be x . U (let w be x. N [U// v])[W#w]
(i , W) (let (i , w) be v. N )[W#w]
pm W as {.. . , (i, X) .ui , . . .} (pm was {... , (i , x).N[ Ui//v]' ... } )[W//w]
(W,W') (l e t (w, x) be v. N )[W#w][W' #x]
pm W as (x, y).U (pm was (x,y) .N[ U#v])[W#w]
thunk M N [t hunk M Iv]
ll to x. M -i: K (letstk q. changestk k . (letstk v .
changestk q. N ) to x. M)[K//k]
i -: : K (l e t s t k q .changestk k . i' l e t s t k v .
changestk q.N)[K//k]
W ·::K (letstk q .changestk k. w'letstk v.
changestk q.N)[W#w , K//k]
W ·whe r e n is L N [W#v][L #n]
{ . . . , Wi ·whe r e i ·:: n , ... } (letstk q. changestk 1. A{ , i .l e t s t k n .
is L changestk q. (N [Wi // V]), } )[L#l]
W ·whe r e x c: n is L (letstk q . changestk 1. AX. letstk n .
changestk q . (N[ W#v ]))[L#l]
M M
let W be x. N (l e t w be x . N )[W#w]
pm W as {. .. , (i, X) .Ni , " ' } (pm was {. .. , (i , X).Ni , . . .})[W//w]
pm W as (x, y).N (pm w as (x, y).N)[W//w]
A{... , i.Ni , " ' } A{. . . , i.Ni , . . .}
i'N i'N
Ax.N Ax.N
V'N (v'N )[V#v]
return V (return v)[V#v]
N to x. P N to x. P
force V (force v)[V#v]
letstk x. N letstk x. N
changestk V. N changestk v. N [V#v]
print c. N print c. N

Figure 7.13. Definitions used in proof of P rop . 83


166 CA LL-B Y-PUSH- VALUE

7.8.6 The StkPS Transform Between Equational


Theories
The StkPS transform fro m CBP V+contro l (incl ud ing stacks) t o JWA,
shown in Fig. 7.4, is extende d to com plex values in Fi g. 7.14.

Ao , .. . , An_1 I-VV : B
let V be x . W l et V be x.W
pm V as {. . . , (i, x). Wi , .. .} pm V as {. . . ,(i, X).Wi, .. .}
pm V as (x, y).W pm V as (x, y) .W
V -vhere n is L let n be L. V
{... , l;i -vhare i-t : n , ... } is L pm L as {.. . , (i , n) .l;i , . .. }
V -vhar e x c: n is L pm L as (x, n) . V
·i gnor e d ,n
Figure 7.14. St kPS Tr an sform On Complex Valu es

P roposition 84 The StkPS transform preser ves su bstit ut ion and prov-
able equality. 0

The rem ainder of this section is a proof of Prop. 80. A natural ap-
pro ach is to t ry t o t rans late JW A back int o CBPV+cont ro l. The ques-
t ion is how to t rans late -' . Two possibiliti es seem natural : eit her as
U( - -+ FO ) or as stk F - (the la t t er is the cant of NJ -SM L) . Either of
t hese wou ld work, but we choose t he former.
Therefore, our inverse t rans lat ion from JWA to C BP V + cont ro l is
given by

StkPS

• CBPV+An s
[F O/Ans]

We wri t e _ f for t he composite transfor m from JWA to CBP V+cont rol


indicat ed in t his di agr am. We will show that t his composite t ransfor m
is inverse t o t he StkPS t ransform up to isomorphism. The heart of the
proof is t hese isomorphisms, which , far from being t rivia l, are full of
r
control effects . In outline, wh en given a value I-v W : A , we first ap ply
J1Lmp- With-Argument 167

_f, giving a term rf f


f-v W f : A without control effects, and then apply
the isomorphisms to obtain a value T f-v W : A with control effects that
transforms back to W (up to provable equality).
We first construct these isomorphisms.

1 For each CBPV value type A , we define a function aA from CBPV


-f
+ control values I' f-v V : A to CBPV+control values r f-v V : A ,
and a function a A: 1 in the opposite direction.

2 For each CBPV computation type B , we define a function a lI from


CBPV+ control values I' f-v V : stk B to CBPV+control values
I' f-v V : stk B , and a function ail in the opposite direction.
f

3 For each JWA type A , we define a function (3A from JWA values
I' f-v V : A to JWA values r f-v V : Af , and a function (3A: l in the
opposite direction.

The definitions are given in Fig . 7.15. It is straightforward to check


that aA and aA: l are inverse up to provable equality and commute with
substitution in I'; similarly for a lI and for (3A.

A
pm V as { . . . , (i , x).(i , a Aix ), . . .}
pm W as {oo . ,(i,x) .(i ,a::;: lx), oo .}
Ax A' pm V as (x ,y) .(aAx,aA'y) pm Was (x,y) .(a::;:lx,'a:4}y)
U!1 thunk Ak.(changestk a Blk.force V)
thunk letstk k.(((aQ.k) 'force W) to x. {})
stk !1 a BV a lilW

FA thunk Ax.(changestk V. return a A1x)


[.J to x. (aAx'force W) -r: -ignored
{. .. , (i, aQ.ix) -vhere i ·:: x, ...} is V
pm W as {oo . , (i , x) .(i -i : aBlx), oo .}
A-tQ (aAx ,aBY) ·wher e x c: y is V pm Was (x,y) .(a::;:lx---:;: a Bly)

A
pm V as {oo. ,(i,x).(i, ,BAiX), oo .}
pm W as {oo . ,(i,x) .(i , ,BAlx),oo .}
Ax A' pm Vas (x ,y) .(,BAx, ,BNY) pm Was (x,y) .(,B::;:lx,rr;}y)
-,A , (x, ()).(,B::;:IX /' V) , X.((,BAx, ()) /' W)

Figure 7.15 . Syntactic Isomorphisms a and ,B used in proof of Prop. 80


168 CALL-BY-PUSH- VA LUE

We have thus proved Prop . 80( 1). It is t hen st raight forward to prove
Prop. 80(2) by inducti on on A .

Lemma 85 1 For any CBPV+cont rol+pr i nt value r f-v V : B , we


can prove

2 For any CBPV+cont rol+pr i nt computation r f-c M : B , we can


prove

3 For any JWA+print valu e r f-v V : B , we can prove


- )
V = ,Bn l V f [,BAi xi! xi ]

4 For any JWA+print nonreturning command r f-n M , we can prove


- -----+
M = Mf[,BA;/Xi , ,{}/k]
T hese resul ts can be extended to computations and valu es with holes
i.e. contexts. 0

T hese are proved by indu ction over te rms .


Lemma 86 1 For any CBPV value ty pe A and value r f-V V : A, we
can prove
a AV = ,BAV
Similarly for comp utation ty pes .
o
This is proved by induction over types.
To prov e Prop. 80(3) , suppose we ar e given a JWA valu e I' f-v W : A ,
where r is the context A o, .. . , Am -I . We set r f-v W : A to be
1 f )
aA: W [a Aixdxi] ' Then - is inverse to the StkPS transform up to prov-
A

able equality, and so the latter defines a bijecti on .


To prove Prop. 80(4), suppose we are given a JWA nonreturning com-
mand I', k : B f-n N , where r is the context A o, ... , Am- I. We set
r f-c IV : B to be letstk k.coerce Nf [aAixdx~ , a Jik/ k]. T hen ~ is
inverse to t he StkPS transform up to provabl e equa lity, and so t he latter
defines a bijection .
T hese arguments can be adapted to values and computations with
holes i.e. contexts.
Chapter 8

POINTER GAMES

8.1 Introduction
8.1.1 Pointer Games And Their Problems
In this chapte r we look at the game semantics of Hyland and Ong
[Hyland and Ong , 2000], discovered also by Nickau [Nickau , 1996]. It is
based on a cert ain kind of two-player gam e, where (generally speaking)
a player moves by
1 pointing to a previous move of the other player ;
2 passing a token.
We call such a game a "pointe r game". This is to distinguish it from
many other kinds of game, such as the purely token-passing games of
[Abram sky et al. , 1994]' which are quite different and which we sha ll
not be looking at. Pointer gam es are ext remely powerful: in a series
of striking results, they have provided universal 1 models for recursion
[Hyland and Ong, 2000], type recursion [McCusker , 1997], cont rol effect s
[Laird , 1997], ground store [Abram sky and McCusker , 1997], general
store [Abramsky et al. , 1998], errat ic choice [Harmer and McCusker,
1999] and more .
However, despite its rem ark able successes, the account of pointer game
mod els in t he literature suffers from a number of problems. The collec-
tive effect of these problems is that the reaction of many readers is
negative. They perceive game semantics as complicated and technical,

l A mo del is u nivers al [Long ley a nd P lot kin , 1997] wh en every morphism from [I'] to [A ] is
t he den ot ation of some te rm I' f- M : A. In the logical set ti ng, t his property is ca lled full
com plete ne ss [Abrarn sky, 1992].

169
P B Levy, Call-By-Push-Value
© Springer Science+Business Media Dordrecht 2003
170 CALL-BY-PUSH- VALUE

and its elegance is obscured. In this chapter, we aim to rectify some of


these problems, but not all. We need to describe the various problems
with some care, in order to say which are the ones we are aiming to
rectify.
1 lack of intuition The rules and constraints of play ar e not clearly
motivated by operational intuitions .

2 difficulty of expression Even when a strategy is int uitively clear,


it is difficult to express it in a clean, rigorous way, as we lack a
convenient language for strategies. This is even more the case for
strategy combinators (e.g. composition) : it is usu ally obvious how
to apply such a combinator in any particular example, but giving a
precise description is messy.
3 difficulty of reasoning Partly because of 2, it is difficult to reason
about game semantics, in particu lar to prove that strategies are equal.
These problems apply to different parts of the account :

• (1) is a problem for the semantics of types and judgem ents.

• (2) is a problem for the semantics of term cons tructors.

• (3) is a problem throughout.


Why do we not consider the semantics of te rm constructors to be affected
by (I)? The reason is that the semantics of term const ru ct ors tends to be
det ermined by the semantics of types and judgements-not in a precise
technical sense , but rather in the sense that, for any given term, t here is
only one "reasonable" denotation of the form sp ecified by the semantics
of types and j udgements. So it is the semantics of typ es and judgements
where t he need for intuitive exp lanation of definit ions is most pressing.

8.1.2 Contribution Of This Chapter


The aim of t his chapter is to solve problem (1) . We aim to give a
motivated acco unt of po int er game semantics, first for JWA and then
for CBPV. We exp lain the arenas, the moves , the pointers and t he ques-
tion/ answer distinction in concrete computational terms .
• An arena gives a type-representation of seve ral jump-points.

• A move represents a jump in JWA or CBPV.


• A pointer represents t he time of receipt of t he jump-point being
jumped to.
Pointer Games 171

• "Asking a question" and "answering" mean forcing a thunk and re-


turning respectively-the two kinds of jump in CBPV.

We recover , of course, the usual pointer game semantics for CBN and
CBV . But the fact that jumps (although not the destination ofreturns)
are explicit it CBPV makes it much more suitable for analyzing pointer
games, and the fact that jumps and their destinations are explicit in
JWA makes it even more suitable.
We make no claim to solve problems (2)-(3) . We emphasize that the
models per se are not new, only the way that we motivate them.

8.1.3 More Is Simpler


It is a remarkable feature of pointer game semantics that the uni-
versal model for a language with divergence, general store (excluding
equality testing on cells) , control effects and infinitary syntax is much
simpler than the universal model for a language without all these fea-
tures (such as PCF) . By including these features from the outset , we can
dispense with the machinery of views, visibility, innocence and bracket-
ing , which obscure the more important asp ects of pointer games. And,
as we see in Sect . 8.5.2, we can simplify the definition of "Q/ A-labelled
arena" , because it becomes possible for an answer-token to succeed an
answer-token (as a consequence of the stk typ e constructor) . The use
of infinitary syntax obviates the need for computability restrictions on
strategies, and gives us definability theorems for types as well as terms.
A further advantage of this formulation is a theorem which is folklore
among games researchers and appears in an indirect formulation in
[Laird, 2003]. It states that the pointer game model for control and
storage is not just universal but also fully abstract , with no need for
the further quotienting which is frequently found in the literature. This
means that all the details of a term's denotation can be worked out by
applying conte xts involving store and control.

8.1.4 Cells As Objects


Our treatment of storage cells exactly follows [Abramsky et al. , 1998];
we regard a cell as an "object with a read method and a write method".

Cells As Objects In CBPV


In CBPV, an A-storing celli can be converted into a thunk that either
• pops the tag write together with a valu e of type A, assigns this value
to l and returns, or
• pops the tag read and returns the contents of l,
172 CA LL-B Y-PUSH- VA LUE

T his has ty pe
U [J {writ e.(A ---+ F1) , read.F A } (8.1)
- recall from Sect . 2.9.2 t hat F1 is the ty pe of commands. We give t he
name pseudoref A to (8.1). T he thunk associated with t he cell l is

thunk A {write. AX. l := x. return


read. read l as y. return y

Sin ce we are excluding cell equality testing from t he la nguage, t his t hunk
gives all the fun ct ion alit y of l . In t he game semant ics, we accordingly
int erpret
• ref A t he same way as pseudoref A
• V: = W . M t he same way as (W 'write ' (force V)) ; M
• read V as y. M t he sa me way as read ' (force V) to y. M .
T hu s, all the d ifficulty lies in the int erpretat ion of nev.

Terms Involving Cells


For t his kind of semantics, it suffices to interpret terms in t he em pty
world, b ecause we interpret a te rm in world wand context r t he sa me
way as a t erm in context

Xo : ref A o, .. . , Xn - I : ref An -I , r

wh er e w has n cells storing ty pes A o, .. . ,An- I. (Here , we are sup posing


an arbit rary orde ring of t he cells .) In part icul ar, t he te rm cell l is
interpret ed the sa me way as X l.

" B a d" Cells


As remarked in [Abramsky et al., 1998], t here are values of type
pseudoref A t hat do not b eh ave like cells. For this reason , definabil-
ity and full abs tract ion t heorems are valid on ly at ref-free ty pes. To
make t hem val id at all types, we can follow [Abramsky et al., 1998] by
int roducing a construct
r f-v V : pseudoref A
r f-v mkpseudo V : ref A
ad d ing suitable ope rational rules. This gives a syntact ic isomorphism
between ref A and pseudoref A . Alternat ively, we ca n defin e r e f A
to b e pseudoref A , again add ing suitable operational rules to treat t he
extra te r ms t hat t his allows to be formed .
Point er Games 173

Cells As Objects In JWA


In JWA, an A-storing celll can be converted int o a jump-p oint t hat
eit her
• accepts the tag write to gether with a value of type A and a jump-
point , assigns t his value to l and then jumps to the jump-point , or

• accepts t he tag read together wit h an A-accepting jump-point, to


wh ich it sends t he contents of l.
This jump-p oint has type

---'I:{write.(A x ---.1) , read .---.A } (8.2)

We give the name pseudoref A t o (8.2) . T he jump- point associated


wit h the cell l is
(writ e, x , k ). l := x . (() ? k)
, { (read, k }, read l as y. (y ? k)

Again, since we are excluding cell equality testing from t he langu age,
this thunk gives all t he functionality of l . In the game semantics, we
accordingly inter pret

• ref A the same way as pseudoref A

• V:= W . M the same way as (writ e, W"O .M) ? V


• read V as y. M t he same way as (read , , y.M ) ? V.
Thus, all t he difficulty lies in the interpretation of new,

8.1.5 Related Work On Abstract Machines


T he work of [Danos et al., 1996] is closely related to ours. The lan-
guage st udied t here is t he sim ply ty pe d CBN A- calculus, with a single
free type identifier L and fun ct ion ty pes but no boolean ty pe . From our
viewpoint, this is a fragment of CBP V (the L type is FO), a frag ment
that does not involve any answer moves.
A jumping abstract machine for t his language had b een presented
in [Danos and Reg nier , 1999]. From our viewpoint , it is t he CBPV
jumping machine obtained via StkPS , restricted to the above-mentioned
fragm ent. (Of course, t his is not how it was motivated in [Danos and
Regn ier , 1999]; it was obtained from a subtle analysis of the Geometry of
Interaction machine for t he multip licative-exponential fragment of linear
logic.) A difference here is that CBPV, and JWA to an even greater
extent, make the control flow explicit (Sect. 1.5.3). So the j umpi ng
174 CALL-BY-PUSH- VALUE

machine for these languages express their op erational intuitions-giving


a "j umping operational semantics"-in a way that cannot be the case
for CBN A-calculus, where force is implicit.
A major result of [Danos et al., 1996J is that the pointer game seman-
tics describes the traces of this machine. This is similar to our use of
jumping traces to motivate pointer game semantics in Sect. 8.3.2. But
a significant difference is that our account is, at present, only informal.
Also related to our work-although not as closely, since we do not
treat innocence-is [Curien, 1998J . The universal arena is the arena
in which there are countably many roots and each token has countably
many successors. An abstract Bohm tree is, roughly sp eaking, a way
of representing an innocent function on the universal arena. (There
are var iations, using other constantly branching arenas.) Because every
arena is embeddable in the universal ar ena, any term of any language
that denote an innocent strategy can be represented as an abstract Bohm
tree. The way in which abstract Bohm trees are composed involves
jumping with arguments, rather like in JWA.

8.1.6 Structure Of Chapter


8.2 Arenas In The Literature
There are some superficial differences between our treatment of arenas
and the various treatments that appear in the literature. For the benefit
of reader familiar with the other treatments, we discuss them here.

8.2.1 PlayerjOpponent Labelling


In [Hyland and Ong, 2000J the tokens of an arena are not labelled
as Player or Opponent, but such a polarity labelling was later intro-
duced in [McCusker , 1996J. This labelling is not actually required for
the definition of the game semantics, and we therefore omit it. After a
model has been defined, its polarization properties can be studied, and
we leave such an analysis-with refer ence to Laurent's model [Laurent ,
2002bJ-to future work.

8.2.2 Tokens Of An Arena


In som e forms of game semantics, a type denotes a game, which is
a set of moves with some additional structure. This is not the case
for pointer game models, where a type denotes an arena (or family of
arenas). It is rather confusing to give the name "move" to an element
of an arena, because a player's move consists of a pointer together with
an arena element. For this reason, we refer to an element of an ar ena as
a tok en.
Pointer Games 175

8.2.3 Arenas Versus Arena Families


CBV pointer games have been present ed in two forms. In [Honda
and Yoshida, 1997J a ty pe denotes an arena with every root lab elled A,
whereas in [Abram sky and McCusker, 1998J a ty pe denotes a family of
are nas . It is clear that t hese are equivalent, since an arena with A-roots
correspo nds to a family of arenas , by removing t he roots. Bu t t here are
disadvan tages in t he arena formulation of [Hond a and Yoshida, 1997J :
for exa mple, the t he interpretati on of -+CBV requires cha nging A-tokens
into Q-tokens.
Likewise for CBN: [Hyland and On g, 2000J and subsequent authors
interpret a CBN type as an arena with every root lab elled Q, but one
could equivalent ly remove the roots and int erpret a CBN type as a fam-
ily of arenas. In the former variant , a closed term on A denotes an
Opponent-first strategy on [A] (where a root can be played only in the
first move). In the latter formulati on , if A denotes { ~hE I then a closed
CBN te rm of type A should deno te a family of Player-first st rate gies
(where a root can be pl ayed at any t ime), one for each arena Rs.
If we use arena families, t hen a CB N fun cti on type is int erpreted
as follows. Suppose A denotes {~ h EI and B denotes {S j }jEJ. Then
A -+CBN B denotes { Pt~I~ l±J Sj }jEJ, where we wri te

• l±J for disjoint uni on

• Pt~I ~ for t he arena with I roots, all labelled Qu estion , and a copy
of R; grafte d underneath t he ith roo t.

It is easy to see t hat t his int erpretati on agrees with t hat in [Hyland and
Ong, 2000], and it makes t he CBPV decomposition more appar ent.
Of cour se the difference between the two presentations is supe rficial,
bu t as with CBV t here are some advantages, for our account , in us-
ing arena familie s. In par ticular , if we int erpret as an arena, the initial
move where the Opponent plays a root does not correspond to a jump
(as moves generally do) but rather to information present in the envi-
ronment / stack before execution begins. Consequently, it is not really
meaningful to lab el it as Qor A, since t hat lab el distinguishes the two
kinds of jump.
[Laurent, 2002aJ advocates interpreting CBV and CBN ty pes in t he
same way. This implies we should eit her interpret both as an arena (as
he does, following [Hyland and Ong, 2000]) or interp ret both as an arena
family. We have argued, for both CBV and CBN , t hat it is preferable
to interpret a ty pe as a n arena family, and t his is what we shall do
throughout.
176 CALL-BY-P USH-VALUE

8.2.4 Forests Versus Graphs


The definition of "arena" vari es in t he literature. In [Hyland and Ong,
2000] an arena is required to be a forest , but in [McCusker, 1996] this
constraint is relaxed and certain more general graphs are allowed. This
seems strange, because arenas are isomorphic if their forest-unwindings
ar e isomorphic, so the forest-unwinding seems to be the "t rue" denota-
tion.
McCusker 's reason for this relaxation was to simplify the interpre-
tation of CBN function type, where a CBN type is interpreted as an
arena. But, as seen in Sect . 8.2.3, no simplification is necessary when
we interpret a CBN type as an ar ena family. So we will follow [Hyland
and Ong, 2000] and insist that an arena be a forest.

8.3 Pointer Game Semantics For Infinitary JWA


+ Storage
We begin out account of pointer games by formulating a model for
infinitary JWA + storage.

8.3.1 Types
Arenas
What information is needed to describe a jump? Let us say that the
jump-points we have available are ko, .. . , km - 1 ' A jump to one of these
is described by the following information:

• the selector i E $m , giving the destination ki

• the argument , which, by Prop. 71, consists of

several tags jo , .. . , j r- 1
several jump-points 10 , . .. , l s- 1

The selector together with the tags ar e called the data of the jump
and they are immediately observable by the context. The jump-points
appear just as points that ar e available for future jumping.
We depict the jumping possibilities ofko , . .. ,km - 1 as a forest -perhaps
infinitely deep-in the following recursive manner. Each choice of data
i, i« ,... , jr -1 is represented as a root (clearly there can be only countably
many) . Under this root we draw the forest depicting the jump-points
10, ... , l s - 1' In the games literature, this forest is called an "arena" .

Definition 8.1 An arena R is a structure (tok R, rt R, f-R)'


• tok R is a countable set whose elements are called tokens.
Pointer Games 177

• rt R is a subset of tok R , whose elements are called roots and I- R is


a binary relation on tok R . We read t I- R u as "t is the predecessor
of u" or as "u is a successor of t" . This must give a "forest", i.e.
unique predecessor each root has no predecessor and each non -
root has a unique predecessor
well-foundedness there is no infinite chain of predecessors

. . . I- R t2 I- R tIl- R to

o
Some useful operations are defined as follows.
Definition 8.2 1 We write 0 for the empty arena.
2 We writ e Rl±JR' for the disjoint un ion of R (writ ing inl r for t he copy
of r E tok R) and R' (writing inr r for the copy of r E tok R') .
3 We writ e ptiE1R;, is t he ar ena with I roots (writing root i for the
ith root) and a copy of R; grafte d underneath the ith roo t (wri ting
under(i , r) for the copy of the token r E tok R;, under ro ot i ).
4 An isom orphism from an ar ena R to an ar ena S is a bijection from R
to S preserving all structure. We wr it e Arenalso for the groupoid
of arena isomorphisms .
5 An arena R is a sub-arena of an ar ena S when tok R ~ tok S and for
all r E tok R
• if r is a root in S then r is a root in R
• if r is a su ccessor of r' in S then r' E tok Rand r is a successor
of r' in R
6 Let a be a token in an ar ena R. T hen we write R ra for t he ar ena
consist ing of those tokens of R hereditarily preceded by a (exclud ing
a its elf) , with the successors of a as roots and the I- relation inherited
from R. (This is not a sub -arena of R , in the above sense.)
o
We have explained that an arena represents t he jumping possibiliti es
of a finit e sequence of jump-points . Since this arena is determined by
the typ e of these j ump-points, we shall say that it type-represents them .
If the arena R type-represents the jump-points ko, ... , km- l , and t he
arena S type-represents t he j ump-points k~ , . . . , k~ _ l ' then R l±J S type-
represents t he concatenated sequence ko, .. . , k m - l , k~ , . . . , k~ _ l ' T his is
178 CALL-BY-PUSH- VALUE

because data for the concatenated sequence must first select which of
the two sequences the destination appears in, and then provide data for
the selected sequence. Likewise the empty arena 0 type-represents the
empty sequence of jump-points.
We will give an informal example of an arena representation. Suppose
we have just one jump-point k accepting 1 + -,A where A is the type

-,(1 + -,(1 + 1)) x -,(1 + 1) + 1

Then the jumping possibilities of k are represented by the arena


inl inr

.> -------------
inl inr

---------/~
Oth : inl Oth: inr 1st : inl 1st : inr

in(~
Here we have omitted the selector wherever there is only one jump-point.
If we jump to k with an inr tag, then there is only one accompanying
jump-point 1, so under the inr root we have not written any selectors. If
we jump to 1 with an inl root then there are two accompanying jump-
points: we can jump to the zeroth with tags inl or inr, and we can jump
to the first with tags inr. This is all represented in the arena.
We emphasize that in a jump whose data is a token a in an arena
R, the jump-points passed are type-represented by Ria. Thus, if we
subsequently jump to one of these jump-points, the data of this jump
will be a successor of a.

Semantics of Types
Now we turn to the semantics of types. A closed value of type A
consists of
• several tags io, .. . , i r - 1

• several jump-points ko, ... ,ks-l


We therefore interpret A as a countable family of arenas {RihE!; each
index i E I represents a tag sequence io, ... , i r - I., and the arena R;
type-represents the jump-points ko, ... ,ks-l'

Definition 8.3 Let {Ril iE! and {Sj} jEJ be countable families of are-
nas.
I
• An isomorphism from {Rili E! to {Sj hEJ is a bijection I - - - - - ' --+-. J
together with an isomorphism from R; to S Ii for each i E I.
Pointer Games 179

• { Rd iEI is a sub-arena-fam ily of {Sj}j EJ when I ~ J and R; ~ S, for


all i E I .
o
We can now give t he semantics of ty pes .
We wan t our semantics of typ es to have t he following properties.
• If A deno tes {~ h EI , then -, A denotes the singleto n family {pt iEI ~} .
This is because a closed valu e 'Yx .M of typ e -,A consists of no tags
and just one jump-p oint that one jumps to taking tags represented
by i E I and jump-points ty pe-represented by R s.
• If, for each i E I , t he type A i denotes {Rij } j EJi' then E i EIAi de-
notes {Rij}( . ')E " ' . J .. This is because a closed value (i , V) of type
t ,) U t EI t
E i EIAi consist s of a tag i E I and tags represented by j i , together
with jump-points type-represented by ~j.
• If A denotes { ~hEI and A' denotes {Sj}j EJ t hen A x A' denotes
h
{ Ri l±J Sj i,j) EI x J. T his is because a closed value (V, V') of ty pe
A x A' consist s of
two sequences of tags, one represented by i E I and one repre-
sented by j E J
two sequ ences of jump-points , one typ e-r epresented by R; and
one ty pe-represe nted by Sj.
• 1 denot es the singleton family containing t he empty arena 0, because
a closed value 0 of t his type consists of no tag and no jump-points.
We use these properties to define the denotation of finitely deep types,
and then interpret an infinitely deep ty pe A (usin g the notation of
Sect . 4.4.2) as U B <1finA [B ]. The above statements then follow. We can
similarly interpret recursive types, up to equality, as in [McCusker , 1996].
Of course, it would be p ossible to interpret a type as an arena rather
than an arena family, but we do not do this because a token in an arena
should represent a possible jump, whi ch an index in [A] does not.
We can now give a definability result for types.
Proposition 8 7 Every countable family of arenas is isom orphic to the
denotation of a ty pe ca nonical form B{~ h EI in type canonical form -
t his is coind uct ively defined as

o
180 CALL-BY-PUSH- VALUE

Proof We define 0 coinductively by

O{RihEI = LiEI,O{Ri ra}aErt Ri

Next, we construct the isomorphism. Since O{ RdiEI denotes an arena


family indexed by I x l , we set the bijection on indexing sets takes i E I
to °i = (i, ()). Then we inductively define a predicate

{RdiEI : i : r M r'

where i E I, r E tok Ri, and r' E tok (O{RihEI h as follows:

j E rt Ri {Ri rj}jErt Ri : j: S M s'

{~h EI : i : j Mval root j {RihEI : i : S M underf" j, s')


We show by induction on n that M defines an arena isomorphism be-
tween the tokens of depth < n in Ri and the tokens of depth < n in
O{RihE1oi' 0
It is often helpful to think of an arena family as a representation of a
type canonical form in this way.
A context r represents a countable family of arenas also, because an
environment for r consists of several tags and several jump-points. We
interpret r = A o, ... ,An- I the same way as we interpret A o x . . . x An-I.

8.3.2 Terms
Semantics of N onreturning Commands
Our next step is to give the semantics of the judgement r f-n M. It will
be recalled from Sect . 2.10 that this is the most important judgement,
as the values are merely auxiliary. We will motivate our semantics with
the command
u : ,(I + ,A) + 1 f-n M

where A is the type

,(I + ,(I + 1)) x ,(I + 1) + 1


and M is shown in graphical form in Fig. 8.1. Notice that it involves a
cell w storing a boolean, and also a cell p storing a jump-point. However,
the cell generation, reading and writing is not visible from the outside.
We write new V =: x rather than new x := V , to conform to the graphical
syntax.
We now wish to describe the externally visible jumping behaviour of
the term. We have to treat two cases : where
• u is bound to inr 0
Point er Games 181

Progr am M

Context q.]

Figure 8.1. Example Program and Context

• u is bound t o inl k, where k is a 1 + -,A acce pt ing jump-point


In t he former case, M merely diverges, so we just consider the lat ter ,
where the behaviour of M is more int eresting. In the followin g narrative,
182 CALL-BY-PUSH- VALUE

we sha ll call a jump pe rformed by t he te rm a "P-move" , and a j ump


performed by t he context an "a -move" . For t he reader 's convenience, a
context is provided in Fig. 8.1 t hat be haves in t he way we describ e.
secretly T he te rm generates a cell x storing true and a cell w storing a
jump-point.
P-move 0 T hen it jumps to t he sole jump-p oint present in t he environ -
ment , viz. k, taking an inr tag and an A-acce pting jump-point.
a-move 1 Suppose the context jumps to t he sole jump-point it received
in P-move 0, taking an inl t ag and 2 jump-points, whi ch we call t he
zeroth and the first. The zeroth accepts 1 + ,(1 + 1), while the first
accepts 1 + 1.
secretly T hen the term sees that x is set to true , sets it to false and
stores in w the first jump-p oint received in a-move 1.
P-move 2 The te rm t hen jumps to t he zeroth j ump-p oint received in
a-move 1, taking t he tag inl and no jump-points.
a-move 3 Suppose t he context j umps again to t he sole jump-point it
received in P-move 0, taking an inl tag and 2 jump -p oints, which we
call t he zeroth and t he first . T he zeroth accepts 1 + ,(1 + 1), while
t he first accepts 1 + 1.
secretly T hen term sees t hat x is set to false.
P-move 4 So it jumps to t he zeroth jump-p oint received in a-move 3,
taking t he tag inr and a 1 + 1 accepting jump-point.
a-move 5 Suppose t he context jumps to t he sole jump-p oint it received
in P-move 4, taking an inr tag and no jump- point .
P-move 6 Then the te rm jump s to the first jump-point it received in
a-move 1 (earlier retrieved from w) , taki ng a inr tag and no jump-
point.
Here is a summary of t he story above.
jump-poin ts in envi ro nment accepting:
move desti nati on of j ump ar gu men t passed cons ists of
received when? selector tags jump-points accepting
P-move 0 environm ent sole Inr A
O-move 1 P-move 0 sole inl 1 + ,(1 + 1), 1 + 1
P-move 2 O-move 1 zeroth inl non e
O-m ove 3 P-move 0 sole inl 1 + ,(1 + 1), 1 + 1
P-move 4 O-move 3 zero th Inr 1+1
O-m ove 5 P- move 4 sole Inr non e
P-move 6 0 - move 1 first Inr non e
Pointer Games 183

Notice that the information about jump-points passed is redundant ,


because it is determined by the type of the destination and the tag
passed. If, for example, one jumps to a -,B x -,B' + -,C accepting jump-
point and one takes an inl tag, then one has to take also a B-accepting
and a B'-accepting jump-point.
We say that a move m points to an earlier move n when m jumps to a
jump-point received in move n. Notice that an O-move always points to
a P-move , whereas a P-move points either to an O-move or-if it jumps
to a jump-point in the original environment-to no move at all. This
is because we ar e only concerned with int eraction between term and
context, so there is no need to record int ernal jumps within the term or
within the context.
Now we turn attention to pointer games. The type of x denotes a
family of two arenas: the empty arena and the following arena R.
inl inr

.>: --------------
inl inr

--------/~
Oth : inl
Oth : inr 1s t : inl 1s t : inr

/
inl --------
inr

We explained this arena in Sect . 8.3.l.


We are able to describe each move by the pointer to a previous move
m (if there is one) , a selector and tags. In each move the selector and
tags can be represented by a token a, and the accompanying jump-points
are type-represented by R fa. The possible tokens in a move are given
as follows.
no pointer When we jump to a jump-point in the environment, the
token must be a root of R , because R type-represents the jump-points
in the environment .

pointer to move m When we jump to a jump-point passed in move


m in which token a was passed, we must pass a root of R fa-Leo a
successor of a-because R fa type-represents the jump-points passed
in move m.
Putting all this together, we can see that the sequence described above
is a play of a game, which we now describe.
Definition 8.4 (informal) The nonreturning-command game on an arena
R is described as follows.
• Play alternates between Player and Opponent. Player moves first.
184 CALL-BY-PUSH- VALUE

• Pl ayer moves by eit her


passing a root r of the source arena R, or
pointing to a previous O-move m and passing a successor r of t he
token passed in move m
• Opponent moves by
pointing to a previou s P-move m and passing a successor of the
token passed in move m .
o
In the next section, we will formally define the notions of play and
strategy for this game.
If a context r denotes the arena family {Ri hE! then a command
r f-n M will denote, for each i E I , a strategy for the nonreturning-
command game on R s, Thus, our example program denotes 2 strategies:
one just diverges (represented as the empty set of plays) , and the other
can behave as in our account above. While we could have made the
choice of i into an O-move, we prefer not to do t his. For the choice is
not part of the execut ion; rather it is incorporated into the environment
long before execution begins.

Formal Definit ion Of Strategy


We begin with a l-player game .
D efi nitio n 8 .5 A j us tifi ed sequence s on an arena R is a triple ( ls l,p, t)
where
length lsi E N U {w}-we write moves s for $Isl and call its elements
moves
pointers a partial fun ction p from moves s to moves s such that p(m) <
m whenever p( m) is defined
tokens a function t from moves s to t ok R
su ch that
• if p(m) is undefined then t(m) is a root of R
• if p( m) is defined then t( m) is a successor of t(p(m)) .
o
We say t hat a move m plays n -rI r when p(m) = nand t (m ) = r. We
say that a move n is descended oddly from a move m when there is a
Pointer Games 185

odd-length chain of pointers from n to m, and descended evenly from m


when there is an even-length chain of pointers. In particular, a move is
descended evenly from itself.
Now we move to the 2-player game.
Definition 8.6 Let R be an arena. A nonreturning-command play (or
just "play" ) on R is a justified sequence s = (ls],p, t) on R such that for
each move m
• if m is even (e.g. 0) then p(m) is undefined or odd
• if m is odd then p( m) is even.
D

We say that a move m in a play is a Player-move if m is even (e.g.


0) and an Opponent-move if m is odd. We say that a play is awaiting
Player if its length is even (e.g. 0), awaiting Opponent if its length is
odd, and infinite if its length is infinite (although infinite plays are not
really required for our semantics).
Definition 8.7 A nonreturning-command strategy (or just "strategy")
on R is a set a of Opponent-awaiting nonreturning-command plays such
that
prefix-closed if s' is an Opponent-awaiting prefix of sEa, then s' E a
deterministic if s, s' E a agree on all but the last move, then they
agree on the last move.
We write nStratR for the cppo of nonreturning-command strategies on
R , ordered under inclusion. Directed joins are given by union, and the
least element is the empty set. D

We say that a justified sequence s is included in a strategy a when s is


a play and all its Opponent-awaiting prefixes of s are in a.

Semantics of Values
Let r be a context of jump-points ko : ,Ao, ... ,km- l : ,Am - 1 type-
represented as the arena R. Suppose we have , defined in context r , some
jump-points Vo, ... , Vn - 1 type-represented as the arena S . The jumping
behaviour of these jump-points begins when the context jumps to one
of them, with
• a selector i E $n and several tags, represented as a root a of S
• several jump-points, type-represented as S ra.
186 CA LL-B Y-PUSH- VALUE

At any time t hereafte r , t he jump-p oint Vi can at any time jump to t hese
jump-points, passing a successor of a, or to one of t he jump-p oints in r ,
passing a roo t of R.
T hus t he execu tion can be described by t he following game .
Definition 8.8 (informal) Let R and 5 be arenas. The value gam e from
R (t he source arena) to 5 (t he target aren a) is described as follows.
• Play alte rn a tes between Player and Opponent. Opponent moves first .
• Each move is classified as
a source mo ve, where a token in R is passed , or
a target mo ve , where a token in 5 is passed .
• Opponent moves initi ally by passing a ro ot T of 5. The initial
move must happen -we do not allow an emp ty play for this game.
(Roughly sp eaking, t he play comes into existence only when Oppo-
nent makes t he initial move.)
• Player moves by eit her
passin g a ro ot T of R , or
pointing to a previous O-move m , and passing a successor r of
t he to ken passed in move m.
• Opponent moves (except in t he initi al move) by pointing to a previous
P-move m , and passing a successo r r of t he token passed in move m.
We give t he name O(R , 5) to t he cpo of st rategies for t his game. D

The read er may wonder why Opponent can pass a root of 5 is t he


initi al move only. Surely the context can jump to one of these jump-
points Vo, . . . , Vn - 1 many times? Indeed it can, bu t t he behaviour each
time will be the same . The jump-points Vo, .. . , Vn - 1 cannot exhibit a
different behaviour each time they ar e jumped to, becaus e, as valu es,
they have no way of generat ing a local cell. So by describing the be-
haviour when the context jumps once to one of these jump-points, we
describ e the behaviour completely. Alternatively, as in [Abram sky et al.,
1998], we could allow t he Opponent to pass a ro ot of 5 in any O-move,
bu t impose a singl e-threadedness condit ion on st rategies to require t he
behaviour to be the sa me each time.
We formalize t he valu e game as follows.
Definition 8.9 A value play from an arena R to an ar ena 5 is a nonem pty
justified sequence s = (I sl ,p, t) on R l±J 5 , such t hat for each move
mE moves s
Pointer Games 187

• if m = 0 then p( m) is undefined and m passes a root of S


• if m is even and positive then p( m) is odd
• if m is odd then either p( m) is undefined and m passes a root of R,
or p( m) is even.
D

We say that a move m in a value play is a Player-move if m is odd and


an Opponent-move if m is even (e.g. 0). We say that a value play is
awaiting Player if its length is odd, awaiting Opponent if its length is
even (but not 0, since the empty sequence is not a play), and infinite if
its length is infinite (although infinite plays are not really required for
our semantics).
Definition 8.10 A value strategy from an arena R to an arena S is a
set (J of Opponent-awaiting value plays such that
prefix-closed if 8' is an Opponent-awaiting (nonempty) prefix of 8 E (J,

then 8' E (J

deterministic if 8,8' E (J agree on all but the last move, then they
agree on the last move.
We write vStrat(R, S) for the cpo of value strategies from R to S, ordered
under inclusion. Directed joins are given by union. D

Notice that we have the isomorphism

vStrat(R, S) ~ TIa Ert snStrat(R l±J S la) (8.3)

It is convenient to take (8.3) rather than Def, 8.9-8.10 as the definition


of vStrat(R, S), although perhaps this is cheating somewhat, because the
initial jump is not represented as a move.
We now consider a more general value r f-v V : B, where r denotes
{RihEI and B denotes {Sj}jEJ. An environment for r consists of some
tags, represented as an i E I, and some jump-points, type-represented
as Ri. For a given i, the value V will consist of some tags, represented
as j E J, and some jump-points type-represented as Sj. By the above
argument, the behaviour of these jump-points will be described by an
value strategy from R; to Sj.
In conclusion, the denotation of V should associate, to each i E I,
some j E J together with a value strategy from 14 to Sj. This is
precisely the interpretation of values presented in [Abramsky and Me-
Cusker, 1998].
188 CALL-BY-PUSH- VALUE

8.3.3 1J-Expansion And Copycat Behaviour


Consider now t he comma nd M' shown in Fig. 8.2. It is almost the
same as the command M in Fig. 8.1- in fact , we can obtain M from
M' by "1-expanding v. So M' and M must have the same denotation,
because our model must validate all the JWA laws, including the "1-Iaws.
Bu t M' has a slightly different behaviour from M , beca use t he jump-
point t hat it passes in P-move 4 is the sam e as the first jump-point
received in O-move 1. So O-move 5 and P-move 6 are act ua lly t he sa me
event .

Figure 8.2. Com mand T hat 1]-Exp an ds to Fig. 8.1

The term M ca n be said to be ""1-expanded" in the sense that an ar-


gument to a jump always consists of tags and , -a bstractions, never iden-
tifiers. It is "1-expanded te rms whose behaviour is described by pointer
game sema nt ics. A term which is not "1-expanded has a less st raight -
forward behaviour , because several jump-p oints can be identi fied , and
hence several consecut ive moves can represent a single jump.
It is possibl e to modify t he jumping operationa l semant ics to imple-
ment , in effect, the "1-expansion of t he code, and t hen t he pointer game
semanti cs would describe the behaviour of all terms, not just the "1-
expanded ones. Bu t t his modified jumping semant ics is less intuitive. It
Pointer Games 189

is also less efficient, both in time because one jump is replaced by several
jumps, and in space because one point is replaced by several points.
In a similar way, the denotation of an identifier x : -,B f-v x : -,B is a
description of the jumping behaviour of its 1]-expansion:

Here, for simplicity, we suppose that B is in type canonical form, so that


just one tag and just one jump-point are passed in each move. We know
that this term denotes a value strategy from an arena to itself.
It immediately obvious that the 1]-expansion always mimics the previ-
ous move of the context by passing the same tag. We argue by induction
that , if the context plays a token in the source arena, then the term plays
the corresponding token in the target arena, and vice versa. We see too
that the term mimics each pointer specified by the term.
• If, in the initial move, the context passes a tag a to our term (playing
a root of the target arena) then the term passes the same tag i to x
(playing a root of the source arena) .
• If, in a non-initial move q, the context passes a tag b to the jump-
point it received in P-move p + 1 (i.e. move q points to move p + 1),
then the term in move q + 1 passes the same tag b to the jump-point
it received in O-move p (i.e. move q + 1 points to move p) . Just
as moves p and p + 1 play the same token in opposite arenas, so do
moves q and q + 1.
This behaviour is called a copycat strategy.

8.4 Semantics Of Terms


We come to the semantics of term constructors. Whereas all the def-
initions we have given so far have been carefully motivated by compu-
tational ideas, we do not attempt to motivate the strategy combinators
in this section. This is because, as we stated in Sect. 8.1.2, there is, for
each combinator that we require, only one reasonable definition.
190 CALL-BY-PUSH- VAL UE

8.4.1 Categorical Structure


As in previous accounts, it is most helpful to use a categorical struc-
ture to organize the semantics. We define it briefly, and leave to P art III
a more thorough exp lana tion of the various requireme nts .
Definition 8 .11 A pre-families JWA mod el cons ists of
• a cartesian category C
• a left C-module i.e. a functor N : Cop ---+ Set
• for each countable family of C-objects {~hEl , a coproduc t-jumpwith
i.e. a C-object ' iEl R; together wit h an isomorphism

II N X XR i ~ C(X, ' iEIRd natural in X .


iEl
o
Such a structure gives us a model of J WA.
• A type (and hence a context) denotes a fam ily of C-obj ects
• If r denotes {Ad iEl and B denotes {B j h EJ t hen a value r f-V B
denotes, for each i E I , some j E J together with a C-mo rphism
Ai • Bj •
• If r denotes {Aih El , t hen a nonreturning command r f-n M denotes,
for each i E I , a N-morphism Ai • i.e. an element of N A i .
• Recursion can be interpret ed using enrichm ent in Cpo" , We leave
the det ails to Sect. 9.5.5.
T his matches what we have seen of the pointer-game model for JWA: C
is the cate gory of arenas and value st rategies, and N R is defined to be
nStratR. For convenience , we define vStrat (R , S) according to (8.3) .
We firstly observe t ha t nStrat is a functor from ArenaIso to Cpo" ,
and everything we sha ll describe is natural as arenas range over ArenaIso.
To define identity morphisms, we require the following .
Definition 8.12 Let R be an ar ena and let a E rt R. We defin e a
strategy copycatR,a on R l±J R fa to be the set of Opponent-awaiting
plays satisfying the following conditions.
• The initial move 0 plays root inl a.
• If move m plays O..n inl b then move m + 1 plays root inr b. Descen-
dants of m and m + 1 copy moves back and fort h.
Point er Games 191

back If move q plays p + 1 -II inr b, where p + 1 is descended even ly


from m + 1, then move q + 1 plays p -II inl b.
forth If move q plays p + 1 -II inl b, where p + 1 is descended oddly
from m , then move q + 1 plays p -II inr b.
o
The identi ty on R must be an element of

II nStratR l±J R ra
a Ert R

and we define it to take a E rt R to copycatj, a.


T he following is used to construct both co~position in C and compo-
sition in N .
Definition 8.13 Let R , S , T be arenas . (For readability, we assume
all t hese arenas disjoint ; but t he formal definiti on uses tags.) Suppose
that a E vStrat(R , S) , and T E nStratS l±J T. We define a strategy a\ T E
nStra tR l±J T as follows.
An interaction sequence for these strategies is a j ustified sequence s
on R l±J S l±J T , together with a "t hread-pointer"? from each root move in
R to an earlier root move in S, such t hat

• s rR ,T is a play on R l±J T
• s rS,T is included in T

• s rm, is included in aa, for each move m playing root a E rt S .


Here, s rmmeans all moves hereditarily j ust ified by m , using both point-
ers and t hread-pointers, excluding m itself.
We define a\T to be t he set of all s rR ,T , whe re s is an interaction
sequence and s rR,T is Opponent-awaiting . 0

U T
To define the composite of R • S · T in C, set
(a; T)a to be a \ Ta. The composite of R U • S T in N is
defined to be a\T. These composit ions can be shown to be assoc iative
and respect t he identities.

2T hese t hread -pointers, unlike ordi nary pointers , d o not indi ca t e t he t im e of receip t of t he
jump-p oin t bein g ju mped to . T hey a re act ually redundan t , becau se, in a n int er ac ti on se-
qu en ce, a root move in R belongs t o t he sa me t hread as th e prec ed ing mo ve. However ,
removing t he t hre ad -pointers wou ld complica te ou r definiti on . T he sa me a pplies t o the
t hread-po inters in DeL 8.14.
192 CALL-BY-PUSH- VALUE

The binary product is given by I±J, and the isomorphism

vStrat(X, S) x vStrat(X, S') ~ vStrat(X, S I±J S')

is trivial using functoriality in arena isomorphisms. Naturality in X


follows from naturality of Def. 8.13 in arena isomorphisms. The terminal
object 0 is similar.
The coproduct-jumpwith of a family of arenas {~hEJ is given by
pti EI~' The isomorphism

II nStrat(X x Ri) ~ vStrat(X, ptiEf~)


iEf
is trivial using functoriality in arena isomorphisms. Naturality in X
follows from naturality of Def. 8.13 in arena isomorphisms.

8.4.2 Cell Generation


We explained in Sect. 8.1.4 that ref A is interpreted the same way as
(8.2) . Thus, if A denotes {~hEI then ref A denotes a singleton family,
whose sole element we call refiEI~ . It has 6 classes of token

write, where i E I
written, where i E I
writteni,r where i E I, r E tok R;
read
read, where i E I
readi,r where i E I, r E tok R;

and is depicted as
write, read

/1\
written, .. ·i EI
/I~ read; . . ·i EI
/\
B
We give the semantics of the recursive initialization construct:
r ,X: ref A f-v V: A r,x : ref A f-n M
(8.4)
r l-" newrec x := V. M
Pointer Games 193

For t his we require the following operation.


Definition 8.14 Let S be an arena and let {~hEl be a fam ily of are-
nas. (For readability, we assume all these arenas disjoint; but the for mal
definition uses tags.) Let i E I , let a E vStrat(S l±J refi EI~ ,14) and let
T E nStrat (S l±J refi EI ~ ) . We define newreez,uT E nStrat (S ) as follows .
An interaction sequence for these strategies is a justified seq uence s
on Sl±J refi EI~l±J14 , together a "t hread-pointer" from certain root moves
in S l±J refiE1R; to an earlier root move in 14, such t hat
• s rS is a pl ay on S
• s rS,r ef i E 1 Ri,nothreadptr (that means: we excl ude moves her edi t arily
justi fied by a root move with a t hread-pointer) is included in T
• If move m pl ays root writei-we call t his a write move - then move
m + 1 pl ays m -n written..
• If move m pl ays root read , and t here is no preceding wr ite move, t hen
move m + 1 plays m .r-. read .. If a lat er move n plays m + 1 .r-. readi,a
t hen move n + 1 plays root a, and s rn+l is inclu ded in aa.
• If move m plays root read , and m' p lay ing write , is the most recent
preceding write move , then move m + 1 plays m -n read. , If a later
move n plays m + 1 .r-. read i,a then move n + 1 plays m ' -n written i,a,
and descendants of nand n + 1 copy moves back and for t h .
back If move q plays p .r-. wr itten. j ; where p + 1 is descended evenly
from n + 1, then move q + 1 plays p -n read . j ,
forth If move q plays p + 1 «-. read. j , where p + 1 is descended oddly
from n, t hen mo ve q + 1 p lays p .r-. written. j,
We define newreci,uT to be t he set of all s rs , where s is an int eract ion
sequence and s rs is Opponent-await ing. 0

To inter pret (8.4) , suppose r denot es {Sj }j EJ and A denotes {RdiEI.


Take j E J. Write (i , a) for [V]( j , ()) and wri t e T for [M] (j , ()) denot es
T . Then [newrec x := V. M]j is newreci,uT.
Mutually rec ursive ini ti ali zati on , as defined in Sect. 6.2, is t reated
sim ilarly- we omit details.

8.4.3 Claims
We have not proved the following res ults, but conjecture that t he same
methods used for call-by-value in [Abramsky et al., 1998] work for JWA.
In the following, recall from Sect. 8.1.4 how we int erpret terms in world
'W.
194 CALL-BY-PUSH- VALUE

Claim 88 (soundness and adequacy) Given a configuration w , s, M ,


we write [w , s, M] for [newrec Xi : - s~ . M]. Then
• ifw, s,M "", * w' ,s' , M' then [w , s,M] = [w' , s' , M']
• if w , s , M diverges then [w, s, M] = -.1.
o
Corollary 89 If k : ' LiEI1 f-k M then M (i , ()) /' k iff [M]O
"",*

plays the ith root. Therefore, terms with the same denotation ar e ob-
servationally equivalent. 0

Claim 90 (definability) Suppose that r denotes {Rd iET . Then any


element of Il iEI nStrat(Rd is the denotation of some nonreturning com-
mand r f-n M. 0

We do not have a corresponding definability result for values, because


there is no value from j,lX.(bool x X) to o.

Claim 91 (full abstraction) Observationally equivalent terms have


the same denotation. 0

8.5 Pointer Game For Infinitary CBPV +


Control + Storage
8.5 .1 Pointer Game Via StkPS
The StkPS transform immediately gives us a model for infinitary
CBPV + control + storage (without cell equality testing). Thus every
value type A , every comp utation type B , every context r and every w ,.6.
denotes a countable family of ar enas, and in particular [stk B] = [B].
For reference, here is the semantics of judgements.

• Suppose the context r denotes {Rd iET and the type B denotes {Sj h EJ.
Then a computat ion r f-c M : B denotes an element of

• Suppose the conte xt r denotes {Rdi EI and the typ e A denotes {Sj h EJ.
Then a value r f-V V : A deno tes an element of

• Suppose the context r denotes {Ri h E! , the type B denotes {Sj hEJ
and the type C denotes {Thh ETT. Then a stack fiB f-k K : C (is by
Pointer Games 195

definition a value f ,nil : stk C r- v K : stk B and t herefore) denotes


an element of

Soundness and ad equ acy for t he CBPV mod el follow from t hat of
t he JWA mod el; t his appears to be true also for definability and full
abstraction, bu t the absence of complex valu es makes this derivation
more difficult.

8.5.2 Introducing Questions and Answers


In Sect. 1.5.3 we saw informally that there are two kinds of instruction
in CBPV that cause a jump to anot her kind of a pro gram , viz. force V
and return V. In Sect. 7.4.1 , we made this more precise: these ar e
ind eed the computations transformed by StkPS int o jump commands in
JWA.
Let us now seek to make our pointer game CBPV mod el more in-
formativ e by distingui shing the two kind s of jump. We will give t he
nam e
• quest ion-move to a move t hat represents forcin g

• answer-move to a move that represents returning.


The appropriateness of t hese nam es, espec ially t he former , is debatabl e.
Perhap s we can defend t he "question" te rminology by say ing t hat when
we force a t hunk, we always pass a cont inuation, in add ition to passing
ope rands; bu t this does not seem to be t he most significant aspect of
forcing. In any case, we use t hese nam es for the sake of consiste ncy with
t he lit erature.
We can identify whether a move is a question-m ove or an answer-move
by looking just at the token that is passed in it. Recall that a token a
represents the data of a jump, i.e. a selector i together with som e t ags
jo, ... , jr-I . If the jump-point selected by i is a thunk, then any jump
that passes a is a question-move, so the token should be lab elled Q. If
t he jump-point selected by i is a continuation, t hen any jump that passes
a is an answer-move, so the token should be lab elled A.
This motivates t he following definiti on .
Definition 8.15 • A Q/A-labelled arena (sometimes just called "arena")
is an arena R together with a lab ellin g fun ct ion ).QA : tok R --+
{ Q, A} .
• 0 is the empty Qj A-labelled arena.
196 CALL-BY-PUSH- VALUE

• R l±J R ' is the disjoint union of Rand R '.

• pt~IRi (where I is countable) is the arena with I roots all labelled


Q, and a copy of R; grafted underneath the it h root.

• PtfEI~ (where I is countable) is the arena with I roots all labelled


A, and a copy of R; grafted underneath the ith root.

• We define Q/A-respecting isom orphism , sub-arena and R ra as in


Def. 8.2.
o
Now we give the semantics of types, with explanation. Remember from
Sect. 5.4.5 that in a continuation semantics like this one, when we read
[B] , we should think [stk B].
• stk B denotes the same as B .

• If B denotes {Ri h EI then UB denotes the singleton family containing


pt~IRi ' This is because a closed value of type U B consists of no tag
and just one jump-point, which is a thunk. When we jump to it, we
take (implicitly in CBPV, explicit ly after StkPS) a stack for B, and
this consi sts of some tags represented by i E I and some jump-points
type-represented by Ri.

• If A denotes {~h EI then FA denotes the singleton family containing


ptfEIRi. This is because a stack for FA consists of no tag and just
one jump-point which is a continuation. When we jump to it, we
take a closed value of type A , consisting of some tags represented by
i E I and some jump-points type-represented by Rs.

• If, for each i E I , the type A i denotes {Rij h EJi ' then I:iEIAi de-
notes {Rij}( - -)E '" _ J -' This is because a closed value (i , V) of type
2,) D2 EI 2
I:iEIAi consists of a tag i E I and tags represented by j i, together
with jump-points type-represented by Rij.

• If A denotes {~h EI and A' denotes {Sjh EJ then A x A' denotes


{Ri l±J Sj}(i,j)EIXJ' This is because a closed value (V, V') of type
A x A' consists of

two sequences of tags, one represented by i E I and one repre-


sented by j E J
two sequences of jump-points, one type-represented by R; and
one type-represented by Sj.
Point er Games 197

• 1 denotes the singlet on family containing t he empty arena 0, bec ause


a closed valu e 0 of t his type consist s of a t rivial tag and no jump-
points.

• If, for each i E I , the ty pe B i denotes {~j }j EJi' then TIiEIB i denotes
{~j }(. ')E " ' . J .. This is because a stack i :: K for TIiEIBi consists
t ,J D t EI t
of a tag i E I and tags represented by j i , together with jump-points
ty pe-represented by ~j'

• If A denotes {~ h EI and B denotes {Sj} j EJ then A -+ B denotes


{~ l±J Sj} (i,j )EIXJ ' This is because a stack V :: K for A -+ B consists
of

two sequences of tags, one represented by i E I and one repre-


sented by j E J
two sequences of jump-points, one type-represented by R; and
one type-represented by Sj '

We int erpret infini tely deep types as for JWA in Sect. 8.3.1.

Proposition 92 Let {~ h EI be a countable family of Q/ A-lab elled are-


nas. It is isomorphic to the denotation of a valu e ty pe , and to t he
denota tion of a computation ty pe . 0

Proof We obtain ty pes in t he following class

A ::= L iEI (U », x stk F Ai )


B::= TIiEI(UBi-+FAd
a nd isomorphisms, in the manner of the proof of P rop . 87. 0
Beware, however: distinct types in this class can be isomorphic types in
t he CBPV+control equat ional theory. An example is FUl and U(Ul x
FO) -+ FO . Their denotation differs in the Q/ A-lab elling.
This makes it clear that the Q/ A-labelling is purely informative-to
distinguish the two kinds of jump. Technically sp eaking, the model is
the same as the one withou t Q/ A-lab ellin g, because arenas with different
Q/ A-lab elling are isom orphic in the category of value strateg ies.
T he categori cal structure t ha t organizes Q/ A-lab elled pointer games
is presented in Sect. 9.8.3.

8.5.3 Answer-Move Pointing To Answer-Move


We give a n example of a strategy in whi ch an A-move points to an
A-move, because this possibili ty has not been t reated previously in t he
198 CALL-BY-PUSH- VALUE

games literat ure. Let B be t he computation ty pe U F st k F bool -7


F nat. T his denot es t he singleto n ar ena fam ily

Arena 0

Q A A

I
A

A
/\ A

A closed computation of this type is

Ax.(force x to y. (change s t k y ; return true ))

This (at 0) denotes a P-first strategy for Ar ena OP , as follows.


P-move 0 CBPV t erminology T he comp utation pops t he t hu nk x
and forces it .
game terminology So P layer plays the ro ot Q-token.
O-move 1 game ter m in o logy Now suppose Opponent points to move
o and plays t he A-token.
CBPV t e r m in olo gy This means t ha t t he t hunk x, forced in move
0, returns a cont inuation y to the cont inuation t hat was t hen (and
in fact still is) current .
P-move 2 CBPV terminology Then t he computation returns true
to t his cont inuation y returned in move l.
game terminology So P layer poi nts to move 1 and passes the A-
token for true.

8 .6 Removing Control
The most imp ort ant part of t he chapter , the model for JWA and
CBP V, is now complet e, and we t urn to a more tec hnical topic. Looking
at our model for CBP V with control and storage, we can ask some
questions.
• W hat objects are definab le without stk? Between t hese,
what morphisms are definable without control ope rators?
• Wha t morphisms are definable without non-ground storage? Among
t hese ,
Pointer Games 199

what morphisms are definable withou t any storage?


what morphism s (between finit ely deep arenas) are defina ble with-
out divergence/recursion?
We will not dis cuss the storage and divergence questions here, since they
are in no way spec ific to CBPV. Bu t t he cont rol questi on is relevant to
CBPV, because
• it leads us to a po inter game CBP V model whi ch is not (tec hnically)
a JWA-derived model
• it demonstrates the utili ty of Q/ A-lab ellin g.
For a countable family of Q/ A-labelled arenas {I4 h E/ '
Firstly, obj ect s.
when is it-up to isomorphism-the denotation of a stk-free value type?
When is it-up to isomorphism-the deno tati on of a stk-free computa-
tion type?

Definition 8.16 An arena is stackf ree-in-va lu e when no root and no


successor of an A-token is an A-token . An are na is stackfree-in-stack
when no successo r of an A-token is an A-token. 0

Proposition 93 In t he absence of stk,


• the denotation of a value type A is a countable famil y of stackfree-
in-value arenas .
• t he denotation of a computation typ e B is a countable family of
stackfree-in-stack arenas.
Conversely, every countable fa mily of stackfree-in-value are nas is isomor-
phic to t he denota tion of a valu e ty pe A , and every countable family of
stackfree-in-stack arenas is isomorphic to t he denotati on of a computa-
t ion ty pe B , of the following type can onical f orm

A ..- ~i EIUBi
B TIiE/(UB i -t F A i)
o
P roof Similar to t he proof of P rop. 87. 0
We explain t hese as follows. In t he abse nce of stk, a value consists of
some tags and some thunks, bu t no cont inuations . In t he deno tation of
a valu e ty pe, R; ty pe-represents t he j ump-po ints accompanying the tags
des cribed by i . Since t hese jump-points are all thunks, it is impossibl e
to jump to one of them as an answer-move, and all the root s of R; ar e
200 CA LL-B Y-PUSH- VAL UE

lab elled Q. Similarly, when we return a valu e (passing an A-token a in


an arena R) the jump-points we pass, type-represe nte d by R ra, ar e all
t hun ks, so again a successo r of a cannot be lab elled A. On t he other
hand, t he denotation of a computation ty pe B describes stacks from B ,
and such a stack will contain a cont inuation, so t he roots of t he arenas
in [B ] might be lab elled A.
For morphisms, we require t he following.
Definition 8.17 A brack etable ga me is any game G where moves ar e
classified as Q/A, some moves include a pointer to an earlier move, and
no A-move points to an A-move. 0

Definition 8.18 Let c be a finit e play in a bracket able game G. The


pending Q-move of c is defined as follows.
• If c is of the form

r>. r>: r>.


... Qo Q ... A Q .. . A Q ... A
t hen t he pending Q-move is Qo.
• If c is of the form

r>.
Q .. . A
~
Q ... A
r>.
Q ... A
or of t he form
r>. r>. r>.
.. · A Q ... A Q ... A Q .. . A
--L

(the eart h symbol indica tes the absence of a pointer) , t hen the pend-
ing Q-move does not exist.
o
Thus t he pending Q-move of c, if it exists, is
• an O-move if c is await ing P
• a P-m ove if c is await ing O.
Definition 8.19 Let c be a play in a bracketable game G.
1 Let m be an A-lab elled move in c. We say that m is bracketed when
it points
Point er Games 201

• to the pending Q- move of c r$rn, if it exists


• to nothing , otherwi se.
2 c is P-bracketed when every A-lab elled P-move is bracketed.
3 c is OP-bracket ed when every A-lab elled move is bracketed .
o
Notice that the bracketing condit ions allow us to omit the poi nt ers from
A-moves (either for Player , or for both P layer and Opponent) when
describing a play.
Definition 8 .20 • A st rategy a for a bracketable game G is P-bracketed
when every play in a is P-bracketed.
• If R is st ackfree-in-stack, we write nStratPbrack R for t he set of P-
bracketed st rategies in nStratR.
• If R and S are st ackfr ee-in- stack, we wri te vStratPbrack (R , S) for t he
set of P-bracket ed strategies
o
Proposition 94 Suppose r is stk-free and denot es {RihEI.
• Suppose B is stk-fr ee and denotes {Sj hE J . Then the denotation of
a cont rol-free computation r I- c M : B lies in

II II nStratPbrack u;I±J s,
iE I j EJ

• Suppose B and C are stk-free and denote {Sjh EJ a nd {Tdk EK


resp ectively. Then the denotation of a cont rol-free stack fiB I- k K :
C lies in
II II L vStratPbrack (~ I±J T k , S j)
i EI k EK jEJ

• Suppose A is stk-free and lies in {Sj h EJ . Then the denotation of a


control-free value r I- v V : A lies in
IIL vStratPbrack (n; S j)
iEI j EJ
o
To prove this, each st rategy combina tor mus t be shown to preserve the
bracketing condit ion, and this is accomplished using the techniques of
[Hyland and On g, 2000].
202 CA LL-BY-PUSH- VAL UE

In t he case of com putations , we conjecture a converse . T he det ail ed


pro of still need s to be don e, but we expect t hat t he ca ll-by-value tec h-
niques adapt.
Claim 95 Suppose r is stk-free and denot es {14h El, and t hat B is
stk-free and denotes {5j}jEJ.. Then any eleme nt of

II II nStra tPbrack 14 l±J s,


i EI j EJ

is t he denotation of a cont rol-free comp utation r f-c M : B. o


As an illu st rat ion of the bracketing cond it ion, conside r the following:
thunk AX.
(U' f or ce y) to z .
(V ' f or ce y' ) to z'
return W
Its StkPS t ransfor m (after some simplificat ion) is

Let us think about t he seque nce of events that ca uses return W to b e


exec uted .
a -move 0, labelled Q The contex t for ces t he t hun k. Acco rding t o t he
StkPS transform, it passes a stack, which consists of an op erand X
and a cont inuation k .
P-move 1, labelled Q T he term for ces a thunk y. Aga in, it passes an
operand U and a cont inua t ion viz . to z . . . .
a-move m, labelled A The context (sp ecifically y) ret urns a value, to
t he cont inuat ion passed in move 1, so t his move p oin t s to move 1.
P-move m + 1, labelled Q The te r m forces a t hunk y' . Again , it passes
an operand V and a cont inuation viz. to z' , . ..
a -move n , labelled A The context (sp ecificall y s') returns a value, to
t he continuat ion passed in move m + 1, so t his mo ve point s t o move
m+1
Pointer Games 203

P-move n + 1 The term returns W to the continuation k received in


move 0, so this move points to move O.
Each time the context returns, any return instruction would have k as
its destination, so move 0 is the pending question-move.
III

CATEGORICAL SEMANTICS
Chapter 9

SEMANTICS IN ELEMENT STYLE

Certain parts of this chapter are designated abstract material. They


are needed for Chap. 11 but not for Chap. 10, and may be omitted if
desired.

9.1 Countable vs. Finite


Throughout Part III, we model infinitely wide CBPV and JWA. The
reader interested only in finitary syntax (e.g. for studying realizability
models) should substitute "finite" for "countable" throughout . The re-
verse substitution would not be possible, because, even for infinitely wide
languages, only finite products are required in a value category.

9.2 Introduction
Many categorical structures, e.g. product, can be defined in two styles:
• elem ent style uses a universal property
• natumlity style uses a natural isomorphism.
The element style is easy to define and work with, so this is what we use
in this chapter. We briefly mention the naturality style formulations in
each case, but a proper treatment is deferred to Chap. II.
After presenting in Sect . 9.3 the category theory we require, we review
the semantics of effect-free language in Fig. 3.8-in particular, the use
of distributive coproducts to model sum types.
Then in Sect. 9.5, we then present the basic structure for interpreting
JWA judgements and for interpreting CBPV judgements. At this point,
the only connectives we can interpret are 1 and x. So our next step,
in Sect . 9.6, is to work through the various connectives of CBPV and

207
P B Levy, Call-By-Push-Value
© Springer Science+Business Media Dordrecht 2003
208 CALL-B Y-PUSH- VALUE

JWA giving for each an appropriate categoric al structure in eleme nt


styl e. When we have the structure for each connective, we have a CBPV
adjun ction model or a JWA modul e model.
Finally in Sect. 9.7 we work through the various examples of deno-
tational semantics for CBPV and JWA presented in Part I-II, and see
how they ar e instances of CBPV adjunction mod els and JWA module
models.
At each stage, we describe how to interpret synt ax within t hese cate-
gorical st ructures , and show t hat t he equational laws are validated. T he
reverse pro cess-where we show t ha t any model of the equa tiona l the-
ory is such a categorical structure-is less important. So we defer it to
Ch ap. 10.

9.3 Categorical Preliminaries


9.3.1 Modules
The notion of a module and bim odule for a ca tegory appear in many
places e.g. [Borce ux , 1994 j Carboni et al., 1998] (T here t he relationship
with modules in ring t heory is explained , but t his does not concern us.)
Definition 9.1 Let C be a category. A left C-module N consist s of
• for each A E ob C, a set whose elements we call N-m orphism s from
A-we write A 9 • when 9 is such a morphism
f 9

idjg 9
(l j I') : 9 = I, (I' ;g)
where 9 is a N -morphism. o
Definition 9.2 Let V be a category. A right V-module 0 consists of
• for each B E ob V , a set whose eleme nts we call O-morphisms to
B -we wri te g . B when 9 is such a morphism

9 h

satisfying identity a nd associativity laws


g; id 9
gj(h ;h') = (gjh)jh'
Semantics in Element Style 209

where 9 is a O-morphism . D

We can combine t hese two structures into a bim odule, although we do


not use bimodules until Chap. II.
Definition 9.3 Let C and V be categories. A (C,V) -bimodule M con-
sists of
• for each A E ob C and each B E ob V , a set whose elements we call
M -morphisms from A to B -we write A 9 • B when 9 is such
a morphism
f 9

9 h

g; id 9
g; (h; hI) (g; h) ; h'
(J ;g) ;h f ;(g;h)
where 9 is aM-morphism. D

Abstract material we can charact erize


• a right V- modu le as a functor from V to Set
• a left B-module as a functor from BOP to Set
• a (B, V )-bimodule as a functor from BOP x V to Set.

9.3.2 Homset Functors


T his sect ion is abstract material. It reviews some familiar defini-
tions.
Definition 9.4 For any category V , we write homv for t he hom set func-
tor OP
V x V - --+. Set

(X , Y) r----+ V (X , Y)

(J , h) 1-----7 >.g.(J ;g; h)


210 CALL-BY-PUSH- VALUE
o
Definition 9.5 1 If A is an object of a category V , we write objA for
the functor 1 • V taking the sole object 0 of 1 to A.
2 Given a functor M : BOP x V --+ Set and a B-object B, we write
M(B, -) for the composite

V • 1 x V (objB)x-Z; BOP x V ~ Set

3 Given a functor M : BOP x V --+ Set and a V-object D, we write


M( -, D) for the composite
Op i' BOP 1 BOP x(objD) BOP VMS t
B - --+. X • x -e

4 In particular, for any object D of a category V, we obtain functors


V(D , -) and V( -, D) from horn».
o

9.3.3 Some Notation


Suppose C is a cartesian category. We will often write
k f

• CAB instead of C(A , B) for the set of C-morphisms from A to B


• (abstract material) C_B instead of C(- , B) for the functor from
CoP to Set defined in Def. 9.5 (3).
Suppose C is a cartesian category and N is a left C-module. We will
often write
k 9

• N A instead of N A for the set of morphisms from A.


We will use these notations only when C is cartesian. They enable us
to unify some definitions in Sect. 9.6 and to avoid confusion between
the homset functor for cartesian categories (Sect. 11.3.3) and ordinary
categories.

9.3.4 Locally Indexed Categories


The notion of locally indexed category is essential for interpreting
stacks in CBPV. But, as we shall see in Sect. 11.3.3, it is important
(although not to the same extent) even in the effect-free setting: for
Semantics in Element Style 211

example, in order to describe dis tributive coproducts in naturality st yle.

Let C be a ca tegory.
• For readers familiar with indexed cate gories, a locally C-indexed cat-
egory V is a st rict C-indexed category- i.e. a fun ctor V : CoP ------7
C a t - in which all the fibres V x have the sam e class of obj ect s ob V
and all the reindexing functors Vk ar e identity-on-object s.
• For read ers familiar with enr iched categories, a locally C-indexed cat-
egory is a [COP, Set]-enr iched category.
But for the general reader , we give an explicit definition.
D efinit ion 9.6 A locally C-indexed category consists of
• a class ob V , whose elements we call V -objects and we underline
(except in cases where ob V = ob C)
• for each object X E ob C and each pair of objects Y , Z E ob V , a
set V x(Y , Z) , an eleme nt of which we call a V-morphism and wri te
1
x
• for each object X E ob C and each obj ect Y E ob V , an identity
id
morphism Y , Y
x
1 9
x x

• for each V-morphism Y _ _ 1_ _ • Z and each C-morphism


x
k k* 1
X ' - - -- . X , a reindexed V-morphism Y - - x-,- '" Z

such that
idi I I k*id id id* I I
I ; id I k* (J ; g) (k* 1); (k*g) (1 ; k) * I l *(k* 1)
(J; g); h I; (g; h)
For a C-object X , we wri te V x for the category of V-obj ects and mor-
phisms over X , also called t he "fibre over X " . If C has a te rminal obj ect
1, morphisms over it are called global mo rphism s. For a C-morphism
Y k , X , we write V X 'Dk . Vy for t he fun ctor that is iden-
ti ty on objects and k* on morphisms , also called t he "reindexing fun ct or
over k" . 0
212 CALL-BY-PUSH- VALUE

As with ordinary categories, we can easily define a notion of "functor" .


Definition 9.7 Let V and V' be locally C-indexed categories. A (locally
C-indexed) functor F from V to V' associates
• to each object Y E ob V an object FY E ob V';
I PI • FZ
x x

such that

Fid id
F(J;g) (FJ); (Fg)
F(k* J) k*(FJ)

Building Locally C-Indexed Categories


We look at some ways of building locally C-indexed categories. The
most important is the following construction (sometimes called the sim-
ple fibration):
Definition 9.8 Let C be a cartesian category. We form a locally C-
indexed category self C as follows:
• the objects are ob C;
I I
z
1r'

I 9
x x
is given by
XxyJ!!..dlxxz 9 • W
f k
z

X' x Y ~ X x Y f • Z

It is easy to verify the identity, associativity and reindexing laws. D


Semant ics in Element Styl e 213

Numero us examples are given as E ilenberq-Mo ore categories:

Definition 9.9 Let (T, "1, fL , t) be a strong monad on a cartes ian cate-
gory C. We write CT for t he locally C-indexed categories in which an
object is a T -algebra a nd a morphism over X from (Y,O) to (Z, ¢) is a
T -a lgebra homomorphism in t he sense of Def. 2.8. 0

As special cases, we have t he locally Cpo-indexed catego ry of cppos and


st r ict maps , and t he locally Set-indexed category of A-sets and A-set
homomorp hisms.
As wit h ordinary ca tegories, we can form pro du cts and oppos ites of
locally C-in dexed categories:

Definition 9 .10 1 Given two locally C-indexed categories V and V' ,


we define the locall y C-ind exed category V x V' by

ob (V x V' ) ob V x ob V'
(V x V' )x ((A , A') , (B , B ')) V x (A , B ) x V'x(AI,B')

wit h t he evid ent identiti es, composit ion and reindexing.

2 Given a locally C-indexed category V , define the locally C-ind exed


oP
category V by

ob V
V x (B , A )

with t he evident ident ities, composit ion and reindexing.


o

9.3.5 OpGrothendieck Construction And Homset


Functors
T his sect ion is abstract material.
When we st udy ord inary categories, we frequently have to consider
fun ctors to Set, in t he setting of homset functors, representable fun ctor s,
adj unct ions, modules etc .
However , we cannot speak of a funct or from a locally indexed category
to Set, because Set is an ordinary category. To remedy t his problem ,
we use the opGrothend ieck cons truc tio n.

Definition 9.11 Let V be a locally C-indexed category, where C is


cartesian. T hen opGr V is t he ordinary category defined as follows:

• an object of opGr V is a pair x Y where X E ob C and Y E ob V ;


214 CALL-BY-PUSH- VALUE

• a morphism from X Y to x! Z in opGr V consists of a pair kf where


X' k • X in C and Y ;, • Z in V ;

• the identity on x Y is given by idid;


• the composite of

xY kf Z 19 W
• X'_ • X"_

is given by l;k((l*J);g).
It is easy to verify the identity and associativity laws. D

Wherever we see a functor from V to Set in ordinary category theory,


we expect to see a functor from opGr V to Set in locally indexed category
theory. As an example, here is the homset functor (cf. Def. 9.4).
Definition 9.12 Let V be a locally C-indexed category. We write
horn-n for the functor
oP
opGr(V x V) • Set

k(J, h) I ) >-.g.(J; (k* g); h)


D

The opGrothendieck const ru ct ion can also be applied in the obvious


way to a locally C-indexed functor V V', giving a functor F.
opGr V ~ opGr V' . Using this, we can adapt Def. 9.5 to the locally
C-indexed setting.
Definition 9.13 1 If A is an object of a locally C-indexed cate gory V,
we write objA for the functor 1 • V taking the sole object
o of 1 to A.
oP
2 Given a functor M : opGr(B x V) ---+ Set and a B-object B, we
write M _(B , -) for the composite

op Gr 'vT"l opGr i
--- op Gr(1 x 'T"l)
v
opGr((obj ~) xV)
• op Gr (BOP x 'T"l)
v
M
--
S et

oP
3 Given a functor M : opGr(B x V) ---+ Set and a V-object D, we
write M _(D, -) for the composite

opGr B ~ opGr(B x 1) opGr(Bx(objl2)~ opGr(BOP x V) ~ Set


Semantics in Element Style 215

4 In particular, for any obj ect D of a locally C-indexed category V , we


obtain fun ctors V _(D , -) and V v _ (- , D) from horn» .
5 Given a functor 0 : opGr V ----+ Set, and a V-object B , we write
V_B for t he composite
o
Cop - -
~
-+. op Gr 1 opGr objQ
• op Gr V - -.... Set
o
9.3.6 Locally Indexed Modules
Just as we define modules for an ordinary cate gory, so we can define
them for a locally ind exed category.
Definition 9. 14 Let V be a locally C-indexed category. A (locally C-
indexed) right V-module 0 consists of
• for each X E ob C and y E ob B, a set whose element s we call 0-
morphisms over X to Y - we write ~ . B when 9 is su ch a
morphism
9 h
• for each 0-morphism X X
9i h
a composite V-morphism
X
k 9
• for each C-morphism X' - - - .... X and O-morphism
X
k*g
a reindexed V-morphism
X'
sati sfyin g identi ty, asso ciativity and reindexing laws
g ; id 9
g; (h; h') (g; h) ; h'
id*g = 9
(k; k')* 9 k*(k' *g)
k*(g; h) (k*g); (k*h)
where 9 is a 0-morphism. o
Simi larly, we can define a left B-module and a (B, V) -bimodule.
Abst ract material we can cha rac te rize
• a right V-module as a fun ct or from opGr V to Set
oP
• a left B-module as a functor from opGr(B ) to Set
OP
• a (B , V)-bimodule as a functor from opGr(B x V) to Set.
216 CA LL-B Y-PUSH- VAL UE

9.3.7 Locally Indexed Natural Transformations


This section is abstract material.
Just as we form a 2-ca tegory Cat of categories, fun ctors and natural
t ransformations , so we can do the same with locally C-ind exed categories.
Definition 9.15 Suppose C has a terminal object. Let V and V ' be
locally C-indexed cate gories and let F and G be fun ct ors from V to V '.
A (locally C-indexed) natural transformation a from F to G provides,
for each obj ect Y E ob V a global morphism FY Ox r . GY such that
f
for each X E ob C and each Y x • Z the diagram

O'or • GY
FY

Ff Gf commutes in V'x.
FZ • GZ
O'o~

Definition 9.16 We write CLI C a t for the 2-category oflocally C-indexed


categ ories, fun ctors and natural t ransformat ions , with t he obvious ver-
tical and hor izontal compos it ions . We extend the opGrothendieck con-
st ruction to a 2-funct or opGr from CLI C a t to Cat in t he obvious way.
o
We ca n talk abo ut monads in CLI C a t , becaus e Def. 1.4 make sense
in any 2-category. The following result was noted in [Maggi, 1991].
Proposition 96 Let C be a car tes ian cat egory. A st rong monad on C
is precisely a monad on self C in CLI C a t . 0

9.4 Modelling Effect-Free Languages


9.4.1 Cartesian Categories and Substitution
Lemma
By (simply typ ed) effe ct-free languag es , we mean x 2::11 ---+-calculus
presented in F ig. 3.8, and various fragments of it , whi ch we nam e by t heir
connectives. T hus "x -calculus" is t he fragment whose only connectives
are 1, x . These are th e key connect ives for catego rical semant ics, becau se
t hey allow us to t urn a conte xt A o, ... , A n- I into a ty pe A o x · ·· x An-I .
For x -calculus , and ot her languages, we say t hat a context m orphis m
[Lawvere, 1963] q from r = A o, ... , A m - I to b. = B o, . . . , B n - I is a
Semantics in Element Style 217

sequ ence of terms M o, ... , M n - 1 where I' I- V M, : B i. (In t he case of


CBPV and JWA , a context morphism will be a sequence of values. ) If we
ar e given such a morphism q and a term b. I- N : C , we can subst it ute M,
for Xi in N, and obtain a term whi ch we write I' I- q* M : C . (Technically
this operation is defined by two inductions: one for weakening, and then
one for general substitution, of which weakening is a sp ecial case. See
[Altenkirch and Reus , 1999; Fiore et al. , 1999] for det ails.)
The fundament al theorem of (simply typed ) categorical semantics is
t hat "models of x -calculus and cartesian categories ar e equivalent " . We
make this st ate ment precise in Sect . 10.2, but for the moment we will
merely describe t he int erpretation of x -calculus in a cartesian ca tegory
C.
Each type denotes a C-ob ject, defined by induction, and the context
A o, ... , A n- 1 denotes the object [A o] x··· x [An- d . Each term I' I- M :
A deno tes a C-morphism [r] [M] . [A] , defined by induction.

[Xi] 1ri
[let M be x. N] (id, [M] )*[N ]
[ (M , M ') ] ([M] , [M' ])
[pm M as (x, y). N] ((id, ([M] ;1r)) , ([M];1r'))*[N]
It is vital to prove that t his soundly int erprets the equational theory,
i.e. that if M = N is provable then [M ] = [N]. But the laws mention
substitution, and so, in order to do this, we first need a substitution
lemma saying what a substit ution denotes:

[q*M] = [q]*[M]
where, if q = (Mo, . .. , Mn- d, we write [q] for ([Mo], . .. , [Mn- d) This
is proved straightforwardly. (Again, two inductions ar e required- see
[Fiore et al. , 1999] for details.) It is then straightforward to show that
the equa tions of the theory ar e validated .

9.4.2 Products, Exponentials and Distributive


Coproducts
If we now extend t he x -calculus by adding count able product typ es,
fun ction typ es or (finite or countable) sum types to t he x -calculus, we
have to add appropriate struct ure to t he cartesian catego ry C, viz. count -
able products, expo nentials or distributive copro ducts. We have alread y
defined t hese structures (in Sect. 1.6.4) , but we now recapi tulate these
definitions in a concise form . This is to fami liarize the reader with this
way of describing universal properties.
218 CALL-BY-PUSH-VAL UE

Definition 9.17 Let C be a cartesian category.


1 A product for a family of obj ects {AihEf consists of an object V (the
7ri
vertex) , together wit h a morphism V • Ai for each i E I ,
such t hat the functions

Cx V ---t IliEf Cx Ai for all X


f f---7 >"i .(J ; 7fd
are isomorphisms-we write qfl x for t he invers e. This is exact ly
Def. 1.3.
2 An expone n ti al from an object A to an object B cons ists of an object
V (t he vertex), together with a morphism V X A ev • B such
that the functions

CxV ---t CXxAB for all X


f f---7 (J x A) ; ev
ar e isomorphisms-we write q-t X for the inverse. This is exactly
Def. 1.6.
3 A distributive coproduct for a fam ily of obj ects {Ad iEf is an object
V (the vertex) together wit h morphisms Ai ini • V such t hat
t he functions

CX xvY ---t IliEf CXXAiV for all X ,Y


f f---7 >"i .((X x in.) "1)
are isomorphisms-we write qL x Y for the inverse. This is exact ly
Def. 1.7.
o
It is clear that the isomorphisms in these definitions correspond to
t he reversible derivations for Il, for -+ and for L:
... r f- B i . .. iEI

r f- IliEf B i

r ,A f- B

rf-A-+B
r,A i f- B . . . iEI
r , L:i Ef A i f- B
Semantics in Element Styl e 219

This is a common pattern throughout the ca tegorical semantics we shall


consider.
The semantics of terms for countable product types using countable
products is given as follows.
[i'M] [M];1fi
[A{ . . . , i.Mi , .. .}] qITAi.[Mi ]
The semantics of te rms for fun ction types using exponentials is given as
follows.
[V'M] ([M] , [V]) ; ev
[Ax.M] q--t[M]
The semantics of terms for sum types using distributive coproducts is
given as follows.
[(i , M)] [M]; ini
[pmM as {... , (i, x). Ni , ... }] (id, [M])*q2:Ai.[Ni]

We call the defin itions in Def. 9.17 elem ent style because we explicit ly
describe what the isomorphism does to an element of the homset. But
we sh all show in Sect. 11.3.1 and Sect. 11.3.3 that these structures can
also be described in naturality styl e, where, in addition to the vertex V ,
we provide
• for a product of {Ad iEJ , an isomorphism

Cx V ~ II Cx A i natural in X
i EI

• for an exponential from A to B , an isomorphism


Cx V ~ CXxAB natural in X

• for a distributive coproduct of {Ai h EI , an isomorphism

CX XV1f*Y ~ II CXx Ai1f*Y natural in X and Y


iEI

This "nat urality in Y" uses the followin g notation. Given a C-morphism
X X Y h
"
Z we write
.

Cx h
CxY - -.... CxZ

for the fun ction taking 9 to (id,g) *h .


220 CA LL -BY-PUSH- VALUE

9.5 Categorical Structures For Judgements Of


JWA And CBPV
9.5.1 Introduction
In this section we interpret the JWA fragment and the CBPV frag-
ment whose only connectives are 1, x . In each case , values are inter-
preted in a cartesian category C.

9.5.2 Judgement Model of JWA


We first recall some fact s about t he J WA equational t heory. T here
are 2 judgements, for values an d nonreturning commands, written

r f-v V : A

Values are to be interpreted in a cartesia n catego ry C, but what abo ut


nonreturning commands? We recall t hat we can substitute a context
morphism r q . b. into a nonreturn ing command b. f-n M to
obtain a nonreturning command r f-n q*M . Substitution satisfies t he
equations

id*M M
p*q*M (p; q)* M

It is therefore clear that we should interpret nonreturning commands in


a left C-module N (Def. 9.1).

Definition 9 .18 A JWA judg em ent model cons ists of

• a cartesian category C

• a left C-module N.
D

T hus we interpret

• a value r f-v V : A as a C-morphism from [r] to [A]

• a nonreturning command r f-n M as a N -morphism from [r]


As usual, we will want a substitution lemma. This will state t hat for
any context morphism r q . b. , and any term P in context b.
(whet her a value or a nonreturning command)

[q* P] = [q]* [P]


Semant ics in Element Styl e 221
Here is the semantics in a JWA judgement model of the JWA fra gment
whose only connect ives ar e 1, x.

[Xi]
[let V be x. P] (id, [V])*[P]
[(V, V')] ([V] , [V'])
[pm V as (x , y). P] ((id , ([V] ;1f)) , ([V] ;1f/))*[P]

9.5.3 Stacks In CBPV


Like in JWA , values in CBPV are interpreted in a cartesian cate gory
C. But how do we interpret the st ack judgement fiB f-k K : C ? Let us
recall some of the operations on stacks.
Firstly we can concatenate a stack flA f-k K : B with a st ack fiB f-k
L : C to give a stack flA f-k K +t L : C. Conc atenation sat isfies the
equations

nil*K
K*nil
(K*L)*L '

Secondly, we can substitute a context morphism I' q . .6. (de-


noting a C-morphism) int o a stack .6.IB f-k K : C to give a st ack
fiB f-k q* K : C. Substitution satisfies the equat ions
id*K K
p*q*K (p; q)*K
Concatenation and substitution ar e related by the equat ions
p*nil nil
p*(K *L)

It is t herefore clear that we require a locally C-index ed categor y (Def. 9.6).


We will interpret a stack fiB f-k K : C as a V-morphism over [I'] from
[B] to [C]. The empty stack nil denotes an identi ty morphism, and we
will want a concate nat ion lemma saying

[K*L] = [K] ; [L]


and a reindexing lemma saying

[q*K] = [q] *[K]


222 CALL-BY-P USH- VALUE

9.5.4 Computations In CBPV


Next we want to interpret the computation judgement r f-c M : B.
We recall t he operations t hat can be performed on comp uta tions .
Firstly we can dismantle a stack fi B f-k K : C onto a computation
r f-c M : B to give a computation I' f-c M e K : C . Dismantling satisfies
t he equa t ions
M e nil M
M e (K *K') (M e K) e K'

Second ly we can substitute a a context morphism r q • .6. (de-


noting a C-morphism) into a computation .6. f-c M : B to give a stack
r f-c q*M : B . Substit ution satisfies t he equations
id*M M
p*q*M = (p; q)*M
Dismantling and substitution ar e related by the equation
p*(M e K) = (p* M) e (p*K)
It is therefore clear t hat we should int erpret computations in a right
V-module (Def. 9.14). We summariz e as follows.
Definition 9.19 A CB PV judgement model consists of
• a cartesian category C
• a locally C-indexed catego ry V
• a right V-module o.
Ob jects of C ar e called val-obj ects , and objects of V are called comp-
objects. 0
We will interpret a computation r f-c M : B as an O-morphism from
[r] to [B] , and we will want a dismantling lemma
[M e K ] = [M] e [K]
and a substitution lemma
[q*M ] = [q]*[M]
Here is the semantics in a CBPV j ud gement model of t he CBPV
fragment whose only connect ives are 1, x .
[Xi] 7ri
[l e t V be x. P] (id, [V ] )*[P]
[(V, V')] ([V ] , [V' ] )
[pm V as (x, y). P ] ((id, ([V]; 7r)) , ([V]; 7r' ))* [P ]
Semantics in Element Style 223

9.5.5 Enrichment
We will not look at enriched models of CBPV and JWA in general,
as the theory has not been developed, but just look at 3 examples of
enrichment. Our main reason for doing this is that in Sect. 9.7 we will
study various constructions of CBPV and JWA models, and we want
to see that these constructions enrich (i.e. can be applied to enriched
models to give other enriched models).
Suppose we want a CBPV judgement model (C ,V, 0) to interpret
CBPV with printing. Then it is not sufficient for each O-homset 0 AB
to be merely a set; it must be equipped with an A-set structure, so
that we can interpret print c. M as c * [M]. Furthermore, in order to
validate the laws

q*(print c. M) print c. (q* M)


(print c. M) • K print c. (M. K)

we require similar equations in the model.


Likewise if we want a JWA judgement model (C,N) to interpret JWA
with printing, we require each N A to be an A-set, and in order to validate

q* (print c. M) = print c. (q*M)

we require a similar equation in the model. This leads us to the following


definition.
Definition 9.20 1 An A-set enriched CBPV judgement model is a
CBPV judgement model (C ,V , 0) where each Ox Y is equipped with
a structure * : A x Ox Y ---+ Ox Y such that the equations

k*(c * g) c*(k*g)
(c*g);h c*(g;h)

hold where 9 is a computation morphism.


2 An A-set enriched JWA judgement model is a JWA judgement model
(C,N) where each Nx is equipped with a structure * : A x Nx ---+
N x such that the equation
k*(c * g) c*(k*g)

holds where 9 is a nonreturning command morphism.


o
224 CA LL-B Y- PUSH- VAL UE

In t he same way, if we want to model CBP V + recurs ion or JWA +recursion


in such a way t hat recursion is interpret ed as a least prefixed point in a
cpo , t hen we require t he following structure .
Definition 9 .21 1 A cppo-enriched CBP V judgem ent model is a CBPV
judgement model (C,7),0) where
• all t he value homset s Cx Y , stack homsets 7)x (Y , Z) and compu-
tation homset s Ox Yare equipped with a parti al order making
t hem cpos, and all operations (compositi on and reindexing) are
cont inuous
• all t he computation homset s Ox Y ar e pointed and t he equations

k*..1 ..1
..1; h ..1

are satisfied for t he least element ..1 of t he computat ion hom set s.
2 A cppo-en riche d JWA judgemen t model is a JWA judgem ent model
(C,N) where
• all t he value homsets Cx Y and nonreturning command hom sets
N x ar e equippe d with a parti al order mak ing t hem cpos , and all
composit ions are continuous
• all t he nonreturning command homsets N X are pointed a nd t he
equation

k*..1 ..1

is satisfied for the least element ..1 of t he nonreturning comma nd


homsets.
o
If we want to restrict at te nt ion to domains (as in Def. 4.8), then we
use t he following.
Definition 9.22 1 A domain- enriched CBP V ju dgem ent mod el is a
cppo -enr iched CBPV judgement model (C , 7) , 0) where all t he com-
putat ion homsets Ox Y ar e domains.
2 A domain-enriched J WA ju dgemen t model is a cppo-enr iched J WA
judgement model (C,N) where all t he nonreturning command hom-
sets N x are domain s.
o
Semantics in Element Styl e 225

Notice that we do not require that value homsets Cx Y be predomains, as


this would not be the case e.g. in the predomain/domain model of CBPV,
where the value homset from N to N is an uncountable flat cpo. The fact
that it is only computation homsets (or nonreturning command homsets)
that are well-behaved is an instance of the phenomenon discussed in
Sect . 2.10: computations are the important judgement.
Abstract material
• An A-set enriched CBPV judgement model (C , D, 0) is a CBPV
judgement model in which 0 is a functor from opGr D to ASet,
rather than just to Set.
• An A-set enriched JWA judgem ent model (C,N) is a JWA judgement
model in which N is a functor from Cop to ASet, rather than just to
Set.
• A cppo enriched CBPV judgement model (C, D, 0) is a CBPV judge-
ment model in a Cpo-enriched sense , in which 0 is a functor from
opGr D to Cpo" , rather than just to Cpo. It is domain enriched if
moreover 0 is a functor to DomStr.
• A cppo enriched JWA judgement model (C ,N) is a JWA judgement
model in a Cpo-enriched sense, in which N is a functor from Cop to
Cpo" , rather than just to Cpo. It is domain enriched if moreover
N is a functor to DomStr.

9.6 Connectives
9.6.1 Right Adjunctives-Interpreting U
In CBPV, we recall that the U connective has the following reversible
derivation
r f-c B
r f-v UB
This suggests the following definition.
Definition 9.23 (element style) A right adjunctive for a comp-object
B in a CBPV judgement model (C,D, 0) consists of a val-object V
(the vertex) together with an O-morphism. fo~e. B, such that
the functions

CxV --+ Ox B for all X


f 1----+ j*force

are isomorphisms-we write qUx for the inverse. D


226 CALL-BY-PUSH- VALUE

Here is t he semant ics of U using right adj unctives.


[force V] [V] *force
[thunk M] = qU[M]
We shall see in Sect. 11.3.1 t ha t the naturality style description of a
right adj unctive for B is the vertex V togeth er with an isomorphism
Cx V ~ Ox B natural in X.

9.6.2 J umpwiths-Interpreting -,
The int erpret ation of -, in JWA is similar to t ha t of U in CBPV. We
recall t ha t -, has the followin g reversible deriva tion
r ,A f-n
r f-v -,A
This suggests t he following definiti on . (The idea of giving a direct cat-
egorical characterization of -, first appeared in [T hielecke, 1997b], al-
t hough t he characterization given t here was different. )
Definition 9.24 (element style) A jumpwith for an object A in a
JWA judgement model (C,N ) consists of an object V (t he verte x) to-
gether with a N-morphism V x A jump. such t hat t he fun ctions

Cx V ---7 Nx - « for all X


f 1----7 (J x A )*j ump

are isomorphisms-we wri te q"'x for the inverse. o


Here is the semantics of -, using jumpwiths.

[V /' W] ([W], [V]) *jump


h x .M ] q"'[M]
We shall see in Sect. 11.3.1 that the naturality style description of a
jumpwith for A is the vertex V together with an isomorphism
Cx V ~ Nx -: « natural in X

9.6.3 Left Adjunctives-Interpreting F


The interpretation of F in CBP V is somew ha t more complicate d, bu t
not mu ch. We recall t hat it has the reversibl e derivation
r ,A f-c f1
f1F A f-k B
Semantics in Element Style 227

This motivates t he following definition.


Definition 9.25 (element style) A left adjunctive for a val-object A
in a CBPV j udgement model (C,V , 0 ) consists of a camp-object V
(the vertex) together with an O-morphism. ret urn . V, such that
A
the functions

V X (V , Y) ---+ OX xAY for all X, Y


h f-----7 (7f'* return ) j (7f* h)
are isomorphisms-we write qFX Y for t he inverse . D

Here is t he sema nt ics of F using left adjuncti ves.


[return V] [V] *return
[M to x. N ] [M] j qF[ N]
[[.J to x. N :: K] (qF[N]); [K]
We shall see in Sect. 11.3.2 t hat t he naturali ty style descript ion of a left
adjunctive for A is t he vertex V together wit h an isomorphism

Cx(V , Y) ~ OX xA7f*Y nat ur al in X and Y .

9.6.4 Products-Interpreting Il
We first extend the notion of categorical produ ct (Def. 9.17( 1)) to a
situation where, as well as a category, t here are some right modules.
Definition 9.26 Let V be a category, an d let {OP}PEP be a family
of right V-m od ules. A product in (V , {OP}PEP) for a fam ily of V -
objects {Bdi ET consists of a V-obj ect V (t he vertex) and a morphism
11";
V • A i for each i E I , such t hat t he functions

V (Y, V ) ---+ TI i EIV( Y, B i ) for all Y


OPV ---+ TIi EI OPn, for all p
h f-----7 )"i.( h; 7fi)

are isomorp hisms. D

Of course, in t he special case that the module fam ily is empty, Def. 9.26
gives t he usu al definition of categorical product in V . But , in general,
it ma kes a st ronger requi rement. We now adapt Def. 9.26 to t he locally
indexed setting .
Definition 9.27 Let C be a category, let V be a locally C-indexed cat-
egory, and let {OP}PEP be a fam ily of right V- modules. A product in
228 CA LL-B Y-PUSH- VALUE

(V , {OP}PEP) for a family of V-obj ect s {B d i EI consists of a V-object


7ri
V (the vertex) to gether with a V-morphism V ----+. B i , such that
t he fun ctions

V x(Y , V) -+ TIiE! V x(Y , B i) for all X , Y


OJ.. V -+ TIiE! OJ..B i for all X ,p
h f-----7 )"i.(h ; O*7fd

ar e isomorphisms. D

T he two cases that are of int erest are


• where the module famil y is empty, giving a definition of product in
a locally ind exed cate gory

• where the module family is singl eton {O} , giving a definition of prod-
uct in a CBPV judgement model (C ,V , 0) .
In the latter case, the isomorphism condition states that the fun ctions

stacks Vx(Y , V) -+ TIiE! V X(Y ,Bi) for all X , Y


computations OxV -+ TI i E!OxBi for all X
h f-----7 )"i.(h; O*7fi)

ar e isomorphisms-we write qn~ Y and qn~ for the inverse. This con-
dition corresponds to the reversibl e derivations for the TI connecti ve in
CBPV:
.. . riA
- B " .. . ~"E!
f-k -~

... r f-c lli . . . iEI


r f-c TIiE!B i
In fact , the isom orphism condit ion for computations is redundant in the
presence of left adj unct ives:

Proposition 97 Let (C, V , 0) be a CBPV judgement model with all


left adjunctives. Then any product in V is automatically a product in
(C ,V , 0). (The converse is trivial.) D

Proof The isomorphism

"'" OX x lY
V x(Fl , Y) .z., "'"
--=---. OxY
Semantics in Element Style 229

maps h to (() * ret urn ) ; h, by calculation. So the diagram


Vx(F1 , V) -+ TI iE! V x(F1 , B i )

~ j~
Ox(F 1, V) - TIiE! OXB i
commutes , by calculat ion. So if the top arrow is an isomorphism, t he
bottom arrow must be too. 0
Here is the semantics of TI, including complex stacks, using products.
[i'M] [M ]; O*7fi
C
[A{. .. , i.Mi , . . . } ] qIl Ai.[M i ]
[i :: K] (O*7fi) ; [K]
[{....«, wh e r e i :: nil, ... } i s L ]
k
(qIl Ai.[Ki ] ) ; [L]
We sha ll see in Sect. 11.3.4 that the na turality style description of a
product for {Bil i E1 in (V , {OP}P EP) is the vertex V together with iso-
morphisms
Vx(Y , V) rv II V x(Y , B i) natural in X and Y
i EI

0>'- V ~ II O>'-B natural in X


i
iE I
mutually natural in Y. T his "mut ually natural in Y " condit ion uses the
following notation. Given an OP-morphism ~ . Y , we wr it e

Vx(Y , Z) OP'Dx (g,Z.~ O>.-Z

for the function taking h to g; h.

9.6.5 Exponentials-Interpreting ----+


We define exponentials in a similar way to Def. 9.26.
Definition 9.28 Let C be a cartesian category, let V be a locally C-
ind exed ca tegory, and let {OP}PEP be a famil y of right V-modules. An
exponential from a C-objec t A to a V-object B consists of a camp-object
V together with a V-morphism V ev . B , su ch t ha t t he functions
A

Vx(Y , V) -T V X xA(Y , B) for all X , Y


0>'- V -T O>'- XAB for all X ,p
h 1------7 ( 7f* h) ; (7f'* ev)
230 CALL-BY-PUSH- VALUE

are isomorphisms. o
Again, the two cases that are of interest are

• where the module family is empty, giving a definition of exponential


in a locally C-indexed category, where C is cartesian

• where the module family is singleton {O}, giving a definition of ex-


ponential in a CBPV judgement model (C , D, 0).

In the latter case, the isomorphism condition states that the functions

stacks Dx(Y , V) -----+ DXxA(Y ,B) for all X , Y


computations Ox V -----+ OxxAB for all X
h f------+ (-7r* h); (1r'* ev)

are isomorphisms-we write q --+~ Y and q--+~ for the inverse. This con-
dition corresponds to the reversible derivations for the -+ connective in
CBPV:
f, AIQ f-k 11
r Ie f-k A -+ B

f,A f-C B
r f-c A -+ B

As with products, the isomorphism for computations is redundant in the


presence of left adjunctives:

Proposition 98 Let (C, D, 0) be a CBPV judgement model with all


left adjunctives. Then any exponential in D is automatically an expo-
nential in (C, D, 0). (The converse is trivial.) 0

Proof Like in the proof of Prop. 97, the diagram

OxV - -_ . OXxAB

commutes, by calculation. So if the top arrow is an isomorphism, the


bottom arrow must be too. 0
Seman tics in Element Styl e 231

Here is t he semantics of -+ , including complex stacks, using exponen-


tials.
[V'M] [M] ; [V] *ev
[.-\x.M] q--+C[M]
[V :: K] ([V] *ev); [K]
[K where x :: nil is L ] (q--+ k[K]) ; [L]
We sha ll see in Sect. 11.3.4 t hat the naturality style descrip tion of an
exponential from A to B is t he vertex V toget her with isomorphisms
'Dx (Y , V) !::::! 'Dx xA(7f*Y ,B) natural in X and Y
O~ V ~ O~ x AB natural in X
mutually natural in Y . This mut ual naturality is defined using t he
OP'Dx (g, Z ) notation as in Sect. 9.6.4.

9.6.6 Distributive Coproducts-Interpreting L


We now extend the notion of dist ributive copro duct to a sit uation
where t here are some left modules.
Definition 9.29 Let C be a cartesian category, and let {NP}P EP be a
family of left C-modules. A distributive coproduct within (C, {Np}P EP)
for a family of C-obj ect s {Ad iEf consists of a C-obj ect V (the ver tex)
in,
together with a C-morphism Ai • V , for each i E I , such t ha t
the fun ct ions

CX xv Y ---+ IliEf CXXAi Y for all X , Y


Nl{ xv ---+ IliEf ~ X Ai for all X ,p
f f----7 .-\i.((X x in.}"1)
are isomorphisms-we write qL X vy and qL x'I for t he inverses. 0

There are 3 cases of int eres t.


cartesian category C Here we take t he module family to be empty.
T his gives us exac tly Def. 9.17(3).
JWA judgement model (C,N) Here we take t he module fam ily to
be t he singlet on {N} . T he isomorphism condition thus state s t hat
t he fun ct ions

values Cx xv Y ---+ IliEf CX XAiY for all X , Y


nonret. commands N x cv ---+ Il iEf Nx c», for all X
f f----7 .-\i.((X x ini) * 1)
232 CALL-BY-PUSH- VALUE

are isomorphisms. This correspo nds to the reversibl e derivations for


I: in JWA:
... r , Ai I-v B ...
r ,I:iEIAi I- v B

... r , Ai 1-" . . . iEI


r , I: iEIAi 1-"
CBPV judgement model (C , D, 0) Here we take the module family
to be N; + N k where
• N c is t he module family containing O_B for each comp-object B
• N k for the module family containing D_(A , B) for each pair of
comp-objects A and B .
The isomorphism condition thus states that the functions

values Cx xvY --7 D iEI CXXAiY for all X , Y


stacks Dx xv(Y ,Z) --7 D iEI DX xAi(Y' Z) for all X , Y , Z
computations Ox xv Z --7 D iEIOX XAiZ for all X , Z
f t---+ .\i.((X x ind * 1)

are isomorphism s. This corresponds to the reversi ble derivations for


I: in JWA :
... r ,Ail- v B ''' iEI
r , I: iEIAi I-v B
r ,Aillil-k Q "' iEI
r , I:iEIAiIB k
I- C

... r , Ai I-c Q ... iEI


r , I:iEIAi I-c C
In all 3 cases, t he semantic equat ions for I: ty pe using a distributive
coproduct are the sa me:

[(1:, V)] [V] ; ini


[pm V as { .. . , (i,x).Pi , ... }] (id, [V])*qI:.\ i ,[Pi]

We shall see in Sect . 11.3.5 that the naturality sty le description of a


distributive coproduct for {A d iEI within (C , {Np }PEP) consists of t he
Semantics in Element Style 233

vertex V together with isomorphisms

CX XV1f*Y ~ IT CXXAi1f*Y natural in X and Y


i EI

Ni xv ~ IT NixAi natural in X
iEI

mutually natural in Y. The "natural in Y" condition uses the Cx h


notation of Sect . 9.4.2, whilst the "mut ually natural in Y" condition
uses the following notation. Given a N-morphism X x Y h " we
write
Cx Y
CN''kh
.
NPx

for the function taking 9 to (id,g)*h.


As with products and exponentials, certain isomorphism conditions
can be redundant.

Proposition 99 Let (C, N) be a JWA judgement model with all jump-


withs. Then any distributive coproduct in C is automatically a distribu-
tive coproduct in (C , N). (The convers e is trivial.) 0

Proof The isomorphism

CX"! ----=----.. N X X 1 - - .... Nx

maps f to (1, ())*jump, by calculation. So the diagram

commutes by calculation. So if the top arrow is an isomorphism, the


bottom must be too . 0

Proposition 100 Let (C , D, 0) be a CBPV judgement model equipped


with all right adjunctives. Then any distributive coproduct in (C,Nk ) is
automatically a distributive coproduct in (C , D, 0) i.e. in (C,Nc U N k ) .
(The converse is trivial.) 0
234 CALL-BY-PUSH- VALUE

Proof The diagram

commutes by calculation. So if the top arrow is an isomorphism, the


bottom arrow must be too. D

9.6.7 Tying It All Together


We can now give our categorical definitions

Definition 9.30 A strong adjunction consists of a CBPV judgement


model (C ,V , 0) with all right adjunctives and left adjunctives. D

Definition 9.31 A CBPV adjunction model consists of a strong ad-


junction with all countable distributive coproducts, all countable prod-
ucts and all exponentials. D

Definition 9.32 A JWA module model consists of a JWA judgement


model (C , N) with all countable distributive coproducts and all jump-
withs. D

Proposition 101 Any CBPV adjunction model, and indeed any strong
adjunction, is isomorphic to one in which the isomorphism

(9.1)

is the identity, and in which therefore

[thunk M] [M]
[force V] [V]

Despite Prop. 101, we do not incorporate this constraint into our defini-
tion of model. For while this constraint is reasonable for certain models
(e.g. Eilenberg-Moore models, as we shall see in Sect . 9.7.2) , for others,
such as continuations, games and possible worlds, requiring (9.1) to be
the identity would detract from the intuitiveness of the presentation.
Semantics in Element Styl e 235

9.6.8 Adjunction s
This section is abstract material. It provides some mathematical
conte xt to Def. 9.30.
To explain the "strong adjunction" terminology, recall t he following.

D efin it io n 9 .33 An adju nction from a category B to a category V


consists of

• two functors

----
F
B ·V
u
(U is called the right adjoint , F is called the left adjoint);

satisfying the triangle laws

UFU - - -· U F

o
This definition makes sense in any 2-categories, so we can sp eak about
adjunctions in CL I Cat. The following result is proved in Sect . 11.6.1.

P r oposi tion 102 Let C be a cartesian category and let V be a locally


C-indexed category. A strong adjunction from C to V corresponds to
adj unct ion from self C to V in CLIC at. 0

Now, in any 2-category, an adjunction (V , U, F , 'fl, E) from B gives rise to


a monad (UF, n, UEF ) on B. So by Prop . 102 and Prop. 96, a strong
adjunction from C gives rise to a strong monad on C- that is the reason
for the terminology "st rong adj unction" .
Conversely, if we are given a monad (T, 'fl, J.L) on B we can look for reso-
lut ions of this monad i.e. adj unctions that give rise to it. As explained in
e.g. [Lamb ek and Scott, 1986], t hese resolu ti ons form a category Res(T ),
when we say t hat a com paris on fun ctor from t he resolu tion (V , U, F , E)
236 CA LL-B Y- PUSH- VAL UE

U'K U
KF F'
KE E' K

It is shown in [Mac Lane, 1971] t hat t here are two canonical ways of
resolving a monad in Cat: t he Eilenberg-Moore resolution , which is
termina l in Res(T ), and t he Kl eisli resolution, whi ch is initi al in Res(T )
(and every comparison fun ctor from it is fully fait hfu l). T hese met hods
exist also in CLICat , where C is any cartesian category. We look a t
Eilenberg-Moore resolu tions in Sect . 9.7.2 and Sect. 11.6.2, and at Kleisli
resolutions in Sect . 11.6.3.

9 .7 Examples
9.7.1 Trivial Models Of CBPV
We saw in Sect . 3.11 t he trivi alization transform from CBPV+ stacks
to t he x 2:IT -+ calculus. T his gives us t he following construc tion on
models.
Definition 9.34 Let C be a countably bicartesian closed category. We
obtain a CBPV adj unction mod el, called a trivial model, by setting t he
stack category to be self C and Ox Y to be Cx Y . Bot h U and F (on
objects) are t he identi ty. 0

Indeed , CB PV adj unction mod el can be thought of as a generalization


of countably bicartesian closed category, where we separate into differ-
ent categories t he dist ributive copro duct requirement an d the count able
product / exponential requirement .

9.7.2 Eilenberg-Moore Models Of CBPV


Suppose we have a cartes ian category C and a st rong monad (T,TI , j.L , t).
We define t he Eil enberg-Moore resolution EM(T ) of this strong monad
(discussed fur ther in Sect. 11.6.2) to be t he following st rong adjunction:

• the value category is C

• t he stack ca tego ry D is t he locally C-indexed category of T -algebras


and T-algebra homomorphisms

• t he comp utation homset Ox (Y, B) is set to Cx Y

• t he right adj unctive U(X, B) is t he carrier X


Sema ntics in Element Style 237

• the left adjunctive F X is the free algebra (TX , p,x).


Under what conditions does it possess distributive coproducts, products
and exponent ials?
Proposition 103 Let (T, "7, fl , t) be a strong monad on a cartesian cat-
egory C.
1 A distributive coproduct of {AdiEI in EM (T) corresponds to a dis-
tributive coproduct of {Adi EI in C.
2 A product of {(Ai, 0d hEI in EM(T) corresponds to a product of
{Ad iEI in C.
3 An exponential from A to (B,O) in EM(T) corresponds to an expo-
nential from A to B in C.
o
The proof of this is straightforward, and uses the construction of product
and exponential algebras given in Def. 1.17.

Corollary 104 The Eilenb erg-Moore resolution EM(T) of the strong


monad (T, "7, u ; t) on C is a CBPV adjunction model iff
• C is countably distributive
• C possesses all countable products of, and exponentials to , carriers of
T-algebras.
o
Abstract material here is a special case.
Corollary 105 Let C be a countably distributive category in which all
idempotents split. Let (T, "7, u;t) be a strong monad on C, and suppose C
possesses all countable Kleisli products (i.e. every product of a countable
family {T AdiEI) and all Kleisli exponentials (i.e. every exponential from
A to TB). Then the Eilenberg-Moore resolution EM(T) is a CBPV
adjunction model. 0

Proof This follows from Cor . 104, because every algebra carrier is a
retract of a free algebra carrier [Mac Lane, 1971]. 0

9.7.3 Between JWA and CBPV


We saw in Fig . 7.1 that JWA can be seen as embedded in CBPV+Ans;
this corresponds to the following construction. Suppose (C ,7),0) is a (A-
setjcppojdomain enriched) CBPV adjunction model, and we are given
238 CA LL-BY-PUSH- VA LUE

a comp-object Ans E ob D . We obtain a (A-set/cppo/ domain enr iched)


JWA mod ule model where

• the value cat egory is C

• t he nonret urning command homsets are given by

N» = Ox Ans

Here are the required isomorphism s.

jumpwith Cx U(A ~ Ans) ~


Ox xAAns
distr. coproduct
values CX x I:iEl Ai Y ITiEl CX XAiY
~

nonret. commands o X x I:iEl A i -Ans ~


ITiEl Ox xAiAns

A spec ial case of this const ruction is where t he CBPV model we begin
with is trivial in t he sense of Def. 9.34. T hus , we are given a countably
bicar tesian closed category C and a n object Ans, and we obtain a JWA
module model with value catego ry C, where Nx is set to be Cx Ans. In
that case, --,A is set to be A ~ Ans, since U is identi ty (on objects).
Som e aut hors e.g. [Hofmann, 1995] have generalized this by noticing
t hat C does not need to be countably bicartesian closed . It is su fficient
t hat C be countably distribut ive, and equipped wit h an expo nential from
A to Ans (whose ver tex we wri te --,A ) for every object A . Moreover ,
every J WA module mo del (C,N) is isomorphic to one arising from such
a (C, Ans)- to show t his, pu t Ans to be --,1. (More technically, t here is a
2-equivalence between t he 2-ca tegory of such (C, Ans) and t he 2-ca tegory
of JWA mod els.)
In t he oppos ite direction, we have a construc t ion corresponding to
the StkPS transform from CBPV+stacks to J WA. Suppose we have a
(A-set/cppo/domain enr iched ) JWA module model (C ,N) . We obtain
a (A-set/cppo/domain enr iched) CBPV adjunction model where

• t he value category is C

• t he stack category is t he locall y C-ind exed category (self ct , so a


morphism over A from B to C is a C-morphism A x C It • B

• t he computation homset s are given by

Ox Y =Nx xY
Semantics in Element St yle 239
Here are the required isomorphisms.

right adjunctive Cx-,B c:>!


N x xB
left adjunctive (self C)o; (-,A , Z) c:>!
N(X XA)X Z
distr. coproduct
values CXx L:iEIAi Y c:>!
ITiEICXXAiY
computations c:>!
ITiEIN(xX Ai)XZ
N( x x L:iE1Ad x Z
stacks (selfC); x L:iEIAi (Y, Z)
c:>!
ITiEI(self C)o; XAi (Y, Z)
product
computations
ITiEI < . L:iE1Bi c:>!
ITiEINx XBi
stacks (self C)o; (Y, L:iE1Bd c:>!
ITiEI(self C)o; (Y, Bi)
exponential
computations NX X( AXB) c:>!
N (XxA) XB
stacks (self C)o;(Y,A x B) c:>!
(self C)o; xA (Y, B)
A model obtained by this construction is called a continuati on mod el.
( "Stack-p assing model" would be a better name in the CBPV setting,
but we use the traditional term.) It is worth noting t hat in every CBPV
adj unction model we have an adjunction between values and stacks, but
in a continua tion model we have, in addition, a duality between values
and st acks.
Putting t hese constructions toget her, we see that , if we are given a
(A-setjcppojdomain enr iched ) CBPV adjunctio n model (C ,V , 0) and
a comp-object Ans E ob V , we obtain a (A-setjcppojdomain enr iched )
continuation model (C, (self C)OP , 0') where

O~Y Ox xyAns
U' B U (B -+ Ans)
F'A U (A -+ Ans)

9.7.4 Erratic Choice


The relation model for erra tic choice present ed III Sect. 5.5.2 IS a
CBPV adjunct ion model, as follows.
• The value category C is Set.
• The stack category ReI is the locally Set-indexed categ ory of rela-
tions i.e. an obj ect is a set and a morphism over A from B to C is a
relation from A x B to C . Usual composition of relations is used.
240 CA LL-B Y-PUSH- VALUE

• The computation morphism s from A to B are relati ons from A to B ,


and we wri te RelAB for t he set of all su ch. Again, usu al compos it ion
of relations is used .

Here ar e the required isomorphisms .

r ight a dj u n ctive Set x 'PB !::::


Relx B
left adjunctive Relx (A , Z ) !::::
Relx xAZ
dist r . copro d uct
values Set X x I: iEI A i Y
rv
ITiEI Set x xAiY
computations ReI X x I:iEI A i Z !::::
ITiEI R el x xAi Z
stacks Rel x x I:iEI A-(Y' Z)
Z
!::::
ITiEI R el x xAi (Y, Z)
product
computations R elx I:iEIBi !::::
ITiEI R elx n,
stacks Relx (Y, I:iEIBi ) !::::
ITiEI Relx (Y, B i )
exponent ia l
compu t a tion s Relx A x B !::::
R el x xAB
stacks R elx (Y, A x B ) !::::
Relx xA(Y, B )

The mode l for erratic choice + divergence with may-t esting equiva-
lence presented in Sect . 5.5.4 is also a CBPV adj unct ion model.

• In t he value category C, an object is a poset and a morphism from A


to B is a pointwise ideal opb imo dule.

• In the locally C-indexed stack category, an object is a poset and a


morphism over A from B to C is an opbimo dule fro m A x B to C .
The identity over A on B relates (a, b) to b' when b ~ b'. Usua l
compos it ion of rela tions is used .

• The comput ation morphisms from A to B ar e opbimodules from A


to B . Usual composit ion of relati ons is used .

9.7.5 Global Store


In Sect . 5.3.3 we saw how to t ranslate CB PV + st acks+global store
into CBPV +stacks. T his corresponds to t he following construction on
mod els. Suppose (C,V , 0 ) is a (A-set jcppo j domain enriched) CBPV
adj unct ion model and we are given a val-obj ect S E ob C. We construct
anot her (A-s et j cppojdomain enr iched ) CBPV adj unction mod el wit h
the same value catego ry C and the same st ack category V by wri ting O S
Semantics in Element Styl e 241

for the right V-module given by

O fY = O s x x Y

We see that (C, V , O S) has all the required isomorphisms.

right adjunctive CxU(S -+ B) ~ O xSB


-
left adjunctive V x(F(S x A) , Z) ~
O f x AZ
distr. coproduct
values CX x I:iEI Ai Y TIiEICX XAiY
~

computations OS Z TIiEIO f x Ai Z

»..
~

X x I:iEIAi-
stacks I: iEIAi(Y ' Z)
~
TIi EI V XX Ai(Y ' Z)
product
computations Of TIiEIBi ~
TIiEIO fB i
stacks V x(Y, TIiEIBi) ~
TI i EI V x(Y, B i)
exponential
computations of A -+ B ~
O f XAB
stacks Vx(Y, A -+ B) ~
V Xx A(Y, B)

We have a similar const ruc t ion for JWA module models, correspond-
ing to a translation from JWA + global sto re to JWA. Given a JWA
module model (C,N) and an object S E ob C we obtain a JWA module
model with the sam e value category C by setting N i = N s -. x . We see
that (C,NS) has all the required isomorphisms.

jumpwith Cx-.(S x A) ~
Ni x A
distr. coproduct
values CXx I:iEIAi Y TIiEICx x AiY
~

nonret . commands NS ~
TIiEINi x Ai
Xx I:iEIA i

9.7.6 Possible Worlds: Part 1


We give the first part of t he possibl e worlds const ruc tion here, but we
finish it in Sect. 11.5, aft er we have treated para metrized represent ability.
Let W be a countable cat egory (i.e. countably many objects and mor -
phisms) whose objects we call "worlds" . For each world w we write w/W
for the countable set I:wlEW C(w,w' ). In t he semantics of Cha p. 6, W
is a poset , so w / W is the set of world s w' ;;::: w . In the spec ial case of
global store, W is the singleton poset.
242 CA LL-BY-PUSH- VALUE

W gives rise to t he following const ruction on models. Suppose t hat


(C,V , 0) is a (A-setjcppojdomain enr iched ) CBPV adjuncti on model,
and we are given a val-object S w E ob C for each world w. Then we ob-
tain a new (A-s etjcppojdomain enr iched ) adj unction model as follows.
• The valu e category is the fun ctor category [W, C], which is cartes ian
(finite product s defined pointwi se).
• In t he stack category, an object is a contravariant fun ctor from Wop
to V I , and a morphism Y ; • Z provides for each world w a
hw
morphism Y w • Z w , such that t he diagram over X w
Xw

hw

O' YJ O' ZJ

Y w' • Z w'
(X f)*( hw')

• The comput ation homsets are given by

O~Y = II O s w x x wY w
w EW

Noti ce t hat if h is an element of t his homset , t here is no na turali ty


constra int between t he various hw- indeed S is not even a functor.
The definiti on of t he connectives at a world w is given as in Sect . 6.8.2,
VIZ.

(UB) w UTI(W', J) EW/W (SW' -+ B w')


(F A) w F L:(W' ,J)EW/W(Sw ' X Aw')
(L: iEI Ad w L:iEIAi w
(A x A')w Aw X A'w
(TIiEIBi )W TIiEIB iw
(A -+ B )w Aw -+ B w
9
The definition of t he connect ives at a morphism w • x makes
use of par ametrized represent ability (Sect . 11.4) whi ch te lls us how to
treat all the connecti ves as fun ct ors. So we defer it to Sect. 11.5.
Semantics in Element Style 243

The category W gives rise similarly to a construction on JWA mod-


ule models, corresponding to a translation from JWA + cell generation
to JWA. Given a (A-set/cppo/domain enriched) JWA module model
(C,N), and an object 8w E ob C for each world 117, we obtain the fol-
lowing (A-set/cppo/domain enriched) JWA module model.
• The value category is [W, ej, which is cartesian (finite products de-
fined pointwise).

• The nonreturning command homsets are given by

Nfc = II Nswxxw
w EW

Again, there is no naturality constraint on elements of this homset.

The definition of the connectives at a world w is given by

(,A)w , L (8w' X Aw')


(w' ,f)Ew/W
(Li EIAi)W LiEIA(UJ
(A x A')w Aw x A'w
9
The definition of the connectives at a morphism 117 • x again
uses parametrized representability and we defer it to Sect. 11.5.

9.8 Families
9.8.1 Composite Connectives
Certain composite connectives have reversible derivations, and it is
generally possible to describe these connectives directly in categorical
terms. We shall treat those examples which are necessary for describing
families constructions.
The most important example is in JWA, where the type 'Li EIAi
satisfies the following reversible derivation
... r, Ai f---n •.• iEI
r f---v 'LiE/Ai

This suggests the following definition.

Definition 9.35 A coproduct-jumpwith for a family of objects {AdiEI


in a JWA judgement model (C,N) consists of an object V (the vertex)
together with a N-morphism V x Ai jump; " for each i E I , such that
244 CALL-BY-PUSH- VALUE

the functions

CxV ----+ IT i EI N x XA; for all X


f 1------7 )"i.((J x Ai) *jumpi)

ar e isomorphisms. o

Clearly, a JWA module mod el will have all countable coprod uc t-j umpwit hs ,
We shall see in Sect . 11.3.1 that , in naturality style, a copro duct-j umpwit h
for {Ad iEI is the vertex V tog ether with an isomorphism

Cx V ~ II Nx -.»; natural in X .
iEI

Similarly, in CBPV, the type PEi EIAi has the following reversible
derivation
. .. f , A i f-c Ii ... iEI
f lFL:iEIAi f-k B

This suggests the following definition.

Definition 9.36 A left coproduct-adjunctive for a family of val-objects


{Ai hE! in a CBPV judgement model (C , 'D, V) consists of a cornp-object
V (the vertex) toge ther with an V-morphism . return ; . V , for each
A;
i E I , such that the fun ctions

'DX(V,Y) ----+ IT i E1V X xA;Y for all X,Y


h 1------7 )"i.(( tt'" retu m. }; (1f* h))

are isomorphisms. o

Clearly a CBPV adjunction model will have all countabl e left copro duct-
adjunctives. We shall see in Sect. 11.3.2 that , in naturality style, a
left coproduct-adj unctive for {Ad i EI is the vertex V toget her with an
isomorphism

'DX(V , Y) ~ II V X x A;1f*Y natural in X and Y


iEI
Semantics in Element Styl e 245

Likewise t he types U ITiEI B i' U(A -t B ) an d U ITiEI(A i -t B i) sat isfy


respectively t he following reversible derivations
... r I- c I1i .. . iEI

r v
I- U ITiEIB i

r ,A I-c B
r I- v U(A -t B)

... r , A i I-c I1i ... iEI


r I-v UITiE1(A i -t B i )
These suggest, resp ectively, the following definitions.
Definition 9.37 Let (C, 'D, 0 ) be a CBPV judgement model.
1 A right product-adjunctive for a family of comp-objects {B ih E! con-
sist s of a val-obj ect V (t he ver tex) tog et her with a morphism
v--.· -Bi ' f or each zt E I , sue h t h at t h e fun ct ions
- -force,
- .

Cx V ---t ITiEI Ox B i for all X


f f-------7 Ai. (J *forcei)
ar e isomorphisms.
2 A right expone nti al-adj unctive from a val-object A to a comp-object
B consists of a val-object V (t he vertex) toget her wit h a morphism
ev • B , such t hat t he fun ctions
VxA
Cx V ---t OX x AB for all X
f f-------7 (J x A) *ev

ar e isomorphisms.
3 A right expone nti al-product-adjunctive for a family of (val-ob ject ,
comp-object ) pairs {(Ai, B i )}iEI consists of a val-object V (t he ver-
tex) together wit h a morphism V~~i ' B i , for each i E I , such
t hat t he fun ctions

Cx V ---t ITiEI Ox xAiB i for all X


f f-------7 Ai.((J x Ai) *evd
are isomorphisms.
246 CALL-BY-PUSH- VALUE
o
Of cour se a CBPV model will have all countable right expo nent ial-
product-adjunctives- and hen ce all countable right product-adjunctives
and all right exponential-adj unct ives. We sha ll see in Sect. 11.3.1 that , in
naturality style, these structures are describ ed by the vertex V together
with an isomorphism from CX V to
right product-adjunctive D i EI Ox B i
right exponential-adjunctive Ox x A u" B
right exponential-product-adjunctive D i EI OX XAi1r*B i

natural in X .

9.8.2 Families Construction For JWA


All the pointer-game models in Ch ap . 8 ar e given by families const ruc-
tions, whose use for denot ational semant ics was introduced in [Abram-
sky and McCusker , 1998]. The most important is the JWA model. We
recapitulate Def. 8.11.
Definition 9.38 A JWA pre-families model is a J WA judgement model
(C , N) equipped with all countable coproduct-jumpwit hs. We write
-,i EI A i for t he vertex of the coproduct-jumpwit h of the family {Ai h EI.
o
Definition 9.39 Let (C,N) be a (A-set/cppo/domain enr iched ) JWA
pre-families mod el. Then we obtain a (A-set/cppo/domain enriched)
JWA module mod el (C',N') as follows. An obj ect of C/ is a countable
f am ily ofC-objects. To describe a C'-morphism from { A h EI to { Bj}j EJ '
we must first give a fun ction between indexing sets I I • J.
Then , for each i E I , we must provide a C-morphism from A i to B [ i-
To describe a N'-morphism from {Aih EI ' we provide, for each i E I , a
N -morphism from A i. In summary :
values C/{A;} iEI {Bo}
J JE
J
0

D i EI L.j EJ CA;Bj
nonret . commands N'{ A;} ;EI D i EI N Ai
Identities and composit ion are defined in the obvious way. The connec-
tives ar e given by
{ AihEI X {Bj } j EJ {Ai X B j} (i,j) EI XJ
1 {I}
L.i EI{ A ij h EJ; { A ij} (i,j )E L.i EIJi
-,{Aih El {-'i El A i}
Semantics in Element Style 247
o

The key examples is the pointer game of model of JWA in Sect . 8.3. An
object is an arena, and the homsets are given by

CRS = vStrat(R , S) N R = nStrat(R )

The connectives are given by

1 X ' i EI
o l±J pt i E I

9.8.3 Families Construction For CBPV


If we want to build a CBPV model where both valu e objects and
computation object s ar e fam ilies, then we require the following .

Definition 9 .40 A pre-families CB P V mod el is a CBPV judgem ent


model (C ,V , 0) , with

• all exponent ials- we wri te A --r B for the ver tex

• all countable right product-adjunctives-we write U i EIB i for the ver-


tex

• all countable left copro duct -adj unct ives- we write F i EI A i for the ver-
tex

Definition 9.41 Let (C,V , 0) be a (A-set/cppo/domain enr iched ) pre-


famili es CBPV model. We define a (A-set/cppo/domain enr iched) CBPV
adjunction model (C' ,V', 0 ') as follows.

• A val-object is a countable famil y of C-obj ects .

• A cornp-objec t is a countable famil y of V-obj ects.

The homsets are given by

value s C{Ad i E/ {Bj hEJ IliEI L: j EJ CA. e,


stacks V {Ad iEI ( {~j h EJ , {Qd kEK) n. . Il k E K L: j EJ V A. (llj , Q k)
computations O{ Ad iE/ {~j h EJ Il iE1 Il j EJ OAJ l -j
248 CALL-BY-PUSH- VAL UE

with t he obvi ous ident it ies, composition an d rein dexing . T he connectives are given
by

1 {I}
{A;} iEI X {Bj} j EJ {Ai x B j} (i,j )EIXJ
L: iEI{Aij h EJi {A ij }(.'t ,)' ) EL-t
"
i EI J t.

{ Ai };EI -+ {~j h EJ { A i -+ ~j} (i ,j ) EI X J


I1i E I {~ij h EJi {~ij} (i ,j ) E L: iEIJi
U {~J i El { Ui EI ~J
F {AihEI {FiEIA i}

We have 4 examples of this.


1 The model in Sect. 8.5.2 is an exa mple. Objects of e and D ar e
Q/ A-labelled arenas. Homsets are given by
e RB vStrat(R, B)
DR(B,T) vStrat(R l±J T , B)
ORB nStrat(R l±J B)

and connectives are given by

1 x
o l±J l±J

2 Take example (1), restrict ob e to stackf ree-in-value are nas (no root
and no successor of an A-token is an A-token) , and restrict ob D to
stackfree -in-stack arenas (no successor of an A-token is an A-tok en).

3 Take exa mple (2), and rest rict to P-b racketed st rategies. T his is the
model of Sect . 8.6.
4 Take exa mple (2), and use instead OP-bracket ed strategies, i.e. strate-
gies for t he game where bo th Player and Opponent are const ra ined
by bracketing.
In Sect . 11.6.4 we shall see more families constructions, for building
CBPV models out of CBN models and out of CBV mod els.
Chapt er 10

ALL MODELS ARE


CATEGORICAL MODELS

10.1 Introduction
We have seen that any cartesian model gives a sound semant ics for
x -calculus, any CBPV adj unction mod el gives a sound semantics for
CBPV, etc. Bu t it is useful to know t hat eve ry model of x -calculus is a
cartesian category, so t hat when we search for cartesian categories, we
are not excluding a potentially interesting model.
To exp ress such a st atem ent, we have to say what we mean by a
"model of x -calculus" , an d t hen our categorical semantics gives a fun ctor
from a category of cart esian categories to a category of models. Our
required resul t will assert that t his fun ctor is an equivalence.
In t his cha pter , we go t hro ugh t his theory for cartesian categories and
x -calculus. We then briefly give ana logous acco unts for CBP V and for
JWA; t hey are essent ially t he same st ory.
We shall see in Sect. 10.2.4 t hat a serio us drawback of our account
is t hat we have to fix object st ruc t ure . So, in a sit uation where the
operat ions on obj ect s (in the catego rical st ruc t ure ) are not the same as
t he operations on types (in the language) , our account would not be
suitable. Fortunately, t his problem does not arise for our cate gorical
semantics. But fur ther work is needed to address it.

10.2 All Models Of x-Calculus Are Cartesian


Categories
10.2.1 The Theorem, Vaguely Stated
Recall t hat x -calculus is the fragment of F ig. 3.8 whose only connec-
tives ar e 1 and x .

249
P B Levy, Call-By-Push-Value
© Springer Science+Business Media Dordrecht 2003
250 CALL-BY-PUSH- VAL UE

We will begin by stating a plau sible result , and then consider what
definitions ar e required to make it true. Here is the result:
Proposition 106 Mod els of x-calculus and cartesian categories are
equivalent. 0

10.2.2 Fixing The Object Structure


Our first step is to describe the semant ics of types:
Definition 10.1 A semantics of typ es fo r x -calculus , also called a x
obj ect structure is a tuple T = (Tob ' 1, x ) consist ing of

• a class Tob , whose element s we call objects ;

• an obj ect 1;
• a binary operation x : Tob X Tob - T Tob

o
We can now repl ace Prop. 106 by the following stronger st atement ;
like Prop. 106 it is not precise bec ause we have not yet defined "mo del
of x -calculus" .
Proposition 107 Let T be a x obj ect structure. Then

• models of x -calculus with semantics of typ es given by T, a nd


• cartes ian cat egories with obj ect structure T.

are equivalent. o
This statement will be easier to make precise than Prop. 106. We will
form two categories and they will be equivalent .
For the purposes of Prop. 107, we need a very specific definition of
cartesian ca tegory.
Definition 10.2 1 A cartesian category is a category C with a distin-
guished te rminal obj ect and distinguished bina ry product s.
2 The objec t structure of a cartesian category C is the x obj ect structure
(ob C, 1, x) where
• 1 is the distingu ished terminal obj ect of C;
• A X A' is the vertex of the distinguished product of t he C-obj ects
A and A' .
o
All Models Are Cat egorical Models 251

As we mention at t he end of Sect. 10.2.4, our approach would not work


if we defined a cartes ian category to be "a category with distinguished
n -ary products for all n E N"
We can now make precise one half of Prop. 107.
D efi n it io n 10.3 Let T be a x object structure. The category C art Cat;
is defined as follows:
• an object is a cartesian category with obj ect st ruc t ure T.

• a morphism is an identity-on-objects functor preserving all structure.


o
Notice that the fixing of T has allowed us to sidest ep the question of
whether a gen eral cartesian functor should preserve structure on the
nose or up to isomorp hism , because the only cartesia n functors we use
ar e identity-on-object s.

10.2.3 What Is A M o d e l Of x-Calculus?


The real problem in making Prop. 107 precise is to give, dir ect from
the equa tional t heory, an a priori notion of "model for x -calculus". The
approac h t hat we use was developed independently in [Jeffrey, 1999] and
in [Levy, 1996].
D efi n it io n lO A Let T be a x obj ect structure (as in Sect. 10.2).
1 A T-sequent is a sequence of obj ect s A o, . . . , A n - 1 toget her with an
object B. It is written A o, . . . , A n - 1 f-- B. Thus, it is a judgement
without a term.
2 A T-signature (or T -multigraph) s provides, for each T-sequ ent
A o, .. . , A n - 1 f-- B , a set s (A o, ... , A n - 1 f-- B) . The elements ar e
called operation symbols with arity A o, . . . , A n - 1 and result typ e B ,
or edges from A o, .. . , A n - 1 to B.
3 We write Sig, for the category of T-signat ur es, where a morphism
from s to s' provides a fun ction from s(Q) to s' (Q) for each T-sequent
Q.
o
The term "multigraph" is some times used becau se, whereas each edge
in a graph has one source object and one target object, each edge in a
mul ti graph has several source objects and one target object .
It is clear t hat , given sema ntics of ty pes T , a semant ics of the f-- judge-
ment for x -calculus is precisely a r-signature s. For s te lls us t hat a term
252 CALL-BY-P USH- VAL UE

A o, .. . , An- 1 f- M : B will denote an edge from [A o], . . . , [An- d to [B] ,


but does not tell us which edge~that will depend on the particular term
M.
We st ill need a way of characte rizing a semant ics of terms for the x -
calculus. The key fact is that , for each object st ruct ure T , th e t erms and
equations of x -calculus define a monad T on Sig. : To see this, suppose
that s is a T-signature; we will build from s another T-multigraph T s as
follows. First, we inductively define the terms built from the signat ure
s , using the rules of x -calculus, toget her with the rule
r f- M o : ao r f- M n - 1 : An- 1

I' f- f(Mo, ,Mn- 1) : B


for each operation symbol f with arity A o, . . . , A n - 1 and result type B
in s . We require the following.
Definition 10.5 A hyper'COng7'Uen ce on terms generated from s is a
congruence '" closed under subst itution. D

We write " ' 8 for the least congruence on these terms containing t he
equat ional laws of x -calculus.
Proposition 108 The congruence "'8 is a hypercongruence. D

We define T s to be the T-multigraph in which an edge from I' to B is an


equivalence class under " ' 8 of terms I' f- M : B built from the signature
s . This new multigraph can be thought of as the "free x -calculus model
generated by s", keeping T fixed throughout. Because of Prop. 108, we
can perform substitution on these equivalence classes.
The rest of the monad structure is given as follows.
• 7]S takes an edge f in s to t he term f(xo , .. . , Xn - l ).

• It S is the "flat te ning transform" : it takes t(Mo, ... , Mn-t} , where t is


)

a
• If s • s' is a multigraph homomorphism, t hen T a repl aces
each occurrence of a fun ction symbol f in a term built from s by
a]: Thus it takes f(M o, . . . , Mn-t} , where f is an edge in s , to
a(J)((Ta)Mo, . .. , (Ta)Mn - 1 ) , and it preserves all other term con-
structors .
We omit the proof t hat T preserves identity and compos ition, 7] and
It are natural and (T, 7], It) satisfies all t he monad laws. These are all
st raightforward inductions.
A ll Models Are Cat egorical Mod els 253

Now let us t hink what information a direct model for x -calculus


should provide.
semantics of types It sho uld provide a x object st ructure T.

semantics of judgement It should provide a T-multigraph s . Then


we know t hat a term A o, ... , A n - I I- M : B is going to denote an
edge from [A o], . . . , [An- d to [B].
semantics of terms Given a ter m A o, . . . , A n - I I- M : B generated
from signatur e s, it sho uld specify t he edge from [A o], . . . , [An- d to
[B ] in s t hat M denotes. Furthermore , provably equal ter ms sho uld
denote t he same edge. T hus t he model should provide a mul ti graph
homomorphism () from I S to s.
In fact , (s, ()) should be an algeb ra for the I monad. We summarize:
Definition 10.6 1 A direct model for x -calculus consists of
• a x object structure T;
• an algebra (s, ()) for t he I monad on Sigr .

2 We write Direct; for the category of direct models for x -calculus


with obje ct structure T. Morphisms ar e algebra homomorp hisms .
o
10.2.4 The Theorem, Precisely Stated
We can now formulate P rop . 107 precisely. We wri te A o x ... x A n - I
for the object (. . . (1 x Ao) .. . ) x An- I .
Definition 10.7 Let T be a x object st ructure. Define a functor

Cart.Cat., ~ Direct,

describing our categor ical semant ics. Explicitly, if C is a cartesian cate-


gory based on T , then define a T-multigraph s by setting s(A o, ... , A n - I I-
B) to be CAoxoo .xAn_1B . We define, by induction, a function [-] from
the mult igraph of terms generate d by s to s . This is given by the se-
mantic equa t ions from Sect . 9.4.1, tog et her wit h an addit ional equation
for ope rat ion symbols:

[f (M o, . . . , Mn-d ] = ([M o], ... ,[Mn- I ] )* f


We define () from I S to s to take t he r-» equivalence class of M to
[M] . That t his is well defined is precisely the conte nt of t he soundness
t heorem: terms related by '> » (i.e. provab ly equa l te rms in t he equat ional
254 CA LL-BY-PUSH- VAL UE

t heory ) have t he sam e denotati on . F inally we define I T(C ) to be (8, 0).


o
Proposition 109 Let T be a x object st ructure . Then t he fun ctor I T
is an equivalence . 0

Proof (outline)

• Let (8, 0) be a direct mod el based on T. Then we construc t a cartesian


category C based on T by setting CAB to be 8(A f-V B) . The structure
is defined in the evident way:

id Oxo
/*g Og(J(xo ))
1f Opm Xo as (Xi, X2). Xl
n' Opm xo as (Xl,X2). x2
(f ,g) O(f( xo) ,g(xo) )
and all requi red equations verified.

• This operati on is inverse to I n up to isomorphism.


o
Our fixing of object st ructure in Prop. 109 sidesteps some subtle co-
herence issues. Ob serve, for example, t ha t if instead of Def. 10.2 we
had defined "cartesia n category " to be "category with dist inguished n -
ary prod uct s for every n E ~r -which clearly ought to be an acceptable
definition- then our approach would not work. Further work is certainly
required to remedy t his prob lem , and we will not consider it fur ther.

10.3 All Models Of CBPV Are CBPV


Adjunction Models
T he direct model/categorical model equivalence result for CBPV pro-
ceeds through exac tly the same st eps as t hat for x -ca lculus in Sect . 10.2.
The first step is to define "object st ruc ture" (mean ing "semant ics of
ty pes" ) in t he obvious way.
D efinition 10.8 A CB PV object structure, is a t uple

T = (Tva lob , Tcom pob , U, L ' 1, x , F , IT, --7 ) consist ing of

• a class Tva lob , whose eleme nts we call val-o bj ects

• a class Tcom pob , whose elements we call camp-o bj ects


All Models Are Categorical Models 255

• a function U : Tcompob ---+ Tvalob

• a function L:i EI : T!alob ---+ Tvalob for every countable set I

• a value object 1

• a binary operation x : Tvalob X Tvalob ---+ Tvalob

• a function F : Tvalob ---+ Tcompob

• a function IT i EI : T{ompob ---+ Tcompob for every countable set I

• a binary operation -t: Tvalob X Tcompob ---+ Tcompob .


o
Clearly any CBPV adjunction model gives us a CBPV object structure.
Next we need to look at signatures for a given object structure.

Definition 10.9 Let T be a CBPV type structure.


1 A T-s equent is r f-v B , or r f-c C or fiB f-k C where r is a sequence
of r-val-objects, B is a T-val-object and Band Care T-comp-objects.

2 AT-signature 8 provides for each sequent Q a set 8( Q).


3 We write Sig, for the category of T-signatures, where a morphism
from 8 to 8' provides a function from 8(Q) to 8'(Q) for each T-sequent
Q.
o
As in Sect . 10.2.3, we need to define a monad 'T on Sig,; Suppose 8
is a T-signature. We induct ively define the terms built from 8 , using all
the rules of CBPV-l-stacks-l-complex values/stacks, together with rules
for the operation symbols in 8 appearing in Fig. ~reffig :sigrules
The reader may find the rules for a stack operation symbol f to
be rather strange. The intention is that f(Vo, ... , Vr-1IM) is a com-
putation whose execut ion begins by executing M , and so the context
f(vo,... , Vr-11['J) is placed onto the stack for future use. This is repre-
sented by the CK-machine transition

r f(Vo, ... , Vr-1IM) B' K C


"M r M B f(Vo , .. . , Vr-11 [.J) :: K C

It is helpful, at this stage, to give a formal definition of dismantling and


concatenation. This is done in Fig. 10.2.
256 CA LL-B Y-PUSH- VALUE

r f-v Vo : Ao ... r l-" VT- 1 : A T- 1


f E s (A o, . . . , A T - 1 l-" B )
r f-v f (Vo , . . . , VT- 1) : B

r f-v Vo : Ao ... r l-" VT- 1 : A T- 1


f E s (A o, . .. , A T - 1 f-C 11)
r f-c f evo, . . . , VT-l) : II

r f-V VO : Ao ... r f-VVr- l : A T- 1 r f-C M : 11


f E s (A o , . . . , A T-dll f-k ll')
r f-C f (Vo, . . . , VT-I IM) : ll'

r f-VVO : A o ... r f-VVT- I : A T- 1 fill' f-k K :Q


f E s (A o , . .. , A T - dll f-k ll')
fi ll f-k ttv«....,VT- 11[·]) :: K : Q

Figure 10.1. Ru les For A Signature s

K M. K
n il M
L
[.J t o x . M :: K (M to x. N) . K
[.J t o x. M :: (K -tt L )
i :: K (i'M) . K
i :: (K -tt L)
V :: K (V 'M) . K
V: : (K -tt L)
let V be x . K let V be x . (M . K )
let V be x . (K -ttL )
pm V as { ... , (i , x ).K i , . . .} pm V as { ... , (i, x ).(M . K i ), .. .}
pm V as { . . . ,(i, x). K i-tt L, ... }
pm V as (x , y ).K pm V as (x , y ).(M • K )
pm V as (x, y ). (K -ttL )
K where nil is K' (M • K) • K'
K where nil i s (K' -ttL)
{. .. , K i where i :: n il , .. .} i s K ' (A{ , i .(M . K i) , .. .}) . K'
{ , K, where i :: nil , .. .} is (K' -tt L )
K where x :: nil i s K ' (Ax. (M . K )) • K'
K whe re x :: nil i s (K' -ttL )
f evo, . . . , VT- d [']) :: K f evo, . .. , VT- dM) • K
f evo, . . . , VT- d [' ]) :: (K -ttL )

Figure 10.2. Dism ant ling and Concatenation (Including Com plex Stacks And Oper-
ation Symbols)
All Models Ar-e Cat egorical Models 257

Definition 10.10 A hyper-congruence on the terms generated from a s


is a congruence closed under substitution, dismantling and concatena-
tion. D

Our next st ep is to write " ' 8 for the least congruence on the terms built
from s cont aining the equa t ional laws of x -calculus.
Proposition 110 The congruence e- is a hyp ercongruence. D

We define T's to be the T-signature associat ing to each T-sequent Q the


set of equivalence classes under " ' 8 of te rms in judgement Q using the
sign ature s, This new multigraph can be t hought of as the "free x -
calculus model generated by s" , keep ing T fixed throughout . Becaus e of
Prop. 110, we can perform substitution, dismantling and concate nation
on these equivalence classes .
The rest of the monad structure is given as follows.

• 'Tfs takes
f in s(Ao, , A n- 1 f-v B) to t he value f(xo , . . . , xn-t}
f in s(A o, , A n - 1 f-v C) to the computation f(xo , ... , Xn - l)

fin s(Ao, , An- l IB f-k C) to the st ack f(xo , ... , xn-l l[- ]) "
nil .

• /1,S is the "flat te ning transform": it takes


a value t (Vo, .. . , ~! - l) , where t is an valu e-edge in T's, to the
)

It preserves all other term const ru ctors; for example, it maps (M , M')
to ((fJ,s)M, (fJ,s)M') .

• s' is a multigraph homomorphism , t hen T o replaces


Q
• If s
each op eration symbol f by of.
We can now formulate our direct model/categor ical model equiva-
lence.
258 CALL-BY-PUSH- VAL UE

Proposition 111 Let T be a CBPV obj ect structure. The "categorical


semantics" functor from CBPV adj unction models on T to the category
of algebras for T on Sig, is an equivalence. 0

Proof (outline)

• The cate gorical semantics functor is defined as follows. Let (C , 'D , 0)


be a CBPV adj unction model based on T. Then we const ru ct a T -
multigraph s by setting

s (A a, , A n- 1 f-v B) to be CAo x x An_l B


s(Aa, , A n- l f-c B) to be 0 Ao x xAn- l B
s (A a, , An- l iB f-k C ) to be 'DAox...xAn_l (B , C)

. We define, by induction, a function [-] from the multigraph of


terms generated by s to s . This is given by the semantic equations
from Sect . 9.5-9 .6, together wit h additional equat ions for operation
symbols:

[f (Va, .. . , Vn -d ] ([Va] , ... , [Vn- 1]) *f


[f (Va, .. . , Vr - t1 M )] [M] ; ([Va] , . . . , [Vn-d )*f
[f(Va, ... , 11;.- 11[·]) :: K ] ([Va ] , ... , [Vn- 1]) *l: [K ]

We define 0 from T's to s to take t he " ' 8 equivalence class of P to


[P]' T hat this is well defined is precisely the content of the sound-
ness t heorem: terms related by " ' 8 (i.e. provably equal terms in the
equa tional theory) have the same denotation.

• Let (s,O) be a direct model based on T . T hen we construct a CBPV


adjunction model C based on T by setting

CA B to be s(A f-v B)
'DA(B , C ) to be s(AIB f-k C)
oAB to be s(A f-c B)
The combinators are defined following Fig. 10.3, and all the required
equat ions verified.

• These operations ar e inverse up to isomorphism.

o
All Models A re Cat egorical Models 259

id (in C) (h o
r 9 (g a C- or V-morphism) Og(f(xo))
r h (h a V-morphism) Oh(f(xo)I[·]) :: nil
g j h (g an V-morphism) Oh(xolg(xo))
id (in V) Onil
h ; k (h a V-morphism) Oh(xol[']) :: k(xol[']) :: nil
Opm Xo as (Xl ,X2) . Xl
Opm Xo as (Xl ,X2) . X2
(f ,g) O(f(xo) , g(xo))
force Oforce Xo
qU f Othunk f(x o)
return Oreturn Xo
qFf 0[·] to xi . f( (x o, Xl) ) :: nil
in; O(i , xo)
qI: >.i.gi Opm Xo as {. . . , (Xl , (i , X2 ) )./i ( (Xl, X2)) , . .. }
11"; Oi :: nil
q0>.i .gi ss.
an V-morphism) O>.{ , i. gi (XO), ... }
q0>'i .hi (hi a V-morphism) O{ , (hi(xol[']) :: nil) where i :: nil , . .. } is nil
ev Oxo :: nil
q---> 9 (g a n V- morphism) O>'X l .g((XO, Xl))
q" h (h a V-morphism) O(h((xo, xdl[']) :: nil) where Xl :: nil is nil

Figure 10.3. Adj unction Model Fro m A Direct Model (8,0)

10.4 All Models Of JWA Are JWA Module


Models
The direct mod el/cat egorical model equivalence result for JWA is or-
ganiz ed in exact ly t he same way as that for x-calculus in Sect . 10.2
and that for CBPV in Sect. 10.3. We define JWA object structure in
the obvious way; clearly each JWA module model gives us a JWA ob-
ject structure. If T is a JWA obj ect structure, a T-s equent is eit her
A o, . . . , A n - 1 f-v B or A o, .. . , A n - 1 f-n , where A o, ... , A n - 1 and Bare
r-objects. AT-signature s provides a set s (Q ) for each T-sequ ent Q.
Given a r-signaturc s, we define the set of te rms built from s. These
are inductively defined by the rules of JWA+complex valu es, together
with the rules

r I- Vo : A o . . .
V
r I- Vr -
V
l : Ar - l

v
f E 8 (A o, . . . , A r - l l-" B)
r I- f( Vo, . .. , Vr- l) : B

r I-v Vo : A o . .. r I-v Vr - l : Ar - l
f E 8 (A o, ... , A r - l 1-")
r 1-" f (Vo, ... , Vr- l)
260 CALL-BY-PUSH- VALUE

We take t he least congruence ""s on t hese terms containing the equa-


tional laws of JWA , which as in P rop. 108 and Prop. 110 is a hypercon-
gruence (i.e. closed under substitution), Quotienting by this congruence
we obtain a new signature called T's, T his gives a monad T on t he
category of T-signatures.
Proposition 112 Let T be a CBPV object structure. The "categorical
semantics" functor from JWA module models with object structure T to
the category of algebras for T on Sig; is an equivalence. D

This is proved in the same way as Prop. 109 and Prop. 111.

10.5 Enrichment
In a sim ilar manner to Prop. 111, we can show t hat our categorical
semantics of CBPV + stacks + print in an A-set enr iched CBPV ad -
junction model is an equivalence. And in a simi lar mann er to Prop. 112,
we can show that our categorical semantics of JWA + print in an A -set
enriched JWA module model is an equivalence.
It appears that these 2 theorems could be generalized from printing
to other strong monads sp ecified by algebraic operations an d equati ons
in the manner of [Plotkin and Power , 2002]; but we do not trea t this
here.
Chapter 11

REPRESENTING OBJECTS

This chapter is independent of Chap. 10.

11.1 Introduction
A key concept of category theory is that of representabl e object (or
representation , or un iversal elem ent) . This concept can be defined in
both element style and naturality style-the equivalence of the two defi-
nitions follows from the Yoneda Lemma . So by describing something as
a rep resentable object, we automatically obtain both an element-style
and a naturality-style description.
The main goal of this chapter is to des cribe each of our connectives as
a rep resenting object for a sui table functor. In each case we recover the
element style defin ition given in Chap. 9 as well as the naturality style
definition briefly mentioned there.
It is because our connect ives are representing objects that they are
automatically unique up to unique isomorphism, and there is no need
for any coherence conditions su ch as are required in [Selinger, 2001;
Thielecke, 1997b] and in models for linear logic. c
The functors that our connect ives represent are built out of hom -
set functors. We described the homset functor for ordinary categories
(Def. 9.4) and locally indexed categories (Def, 9.12) , and these suffice
for most of our connectives. But for distributive coproducts and CBPV
products and exponentials, we require other homs et functors.

• In Sect . 11.3.3, we define a sp ecial homs et functor for a cartesian


category C, and use it to define distributive coproduct in C as a
representing object.

261
P B Levy, Call-By-Push-Value
© Springer Science+Business Media Dordrecht 2003
262 CA LL-BY-PUSH- VALUE

• For CBPV product s and expo nent ials, we will see in Sect . 11.3.4
how to glue right modules to a category (in t he manner of [Carbo ni
et al., 1998]) and give an appropriate homset fun ctor , enabling us to
cha racterize t hese structures as representing objects.
• T he most difficul t case is in Sect. 11.3.5, where we t reat a carte-
sian category with some left modules. This was t he st ructure used
in Sect. 9.6.6 to define distributive copro ducts in JWA and CBPV.
Again by gluein g modules, we define a suitable homset fun ctor, and
t hen we can characterize a distributive coprod uct as a representing
object.
We then look at parametrized represe n tabilit y, which show us how to
make each connective int o a fun ctor. We use this firstly to complete
our definition of possible world semantics that we began in Sect . 9.7.6,
and secondly to show that a st rong adj unct ion is indeed an adjunction
(Prop. 102).
Finally, we look at CBV and CBN. We give a categorical struct ure
for each, and see how, for a given CBPV adj unction mod el, we interpret
CB V inside the Kleisli part and CBN ins ide t he co-Kleisli part.
Note Some aut hors use t he te rm "represent at ion" instead of "repre-
senting object" , reservin g t he lat ter term for what we have called t he
vertex. However , "representation" has many ot her meanings.

11.2 Categorical Structures


11.2.1 Joint vs. Separate Naturality
We frequentl y wish to use t he idiom "nat ur al in X and Y " . This
appears to be ambiguous, because it could refer to eit her joint naturali ty
or separate naturality. However , t here is no ambiguity, becaus e it is well
known t ha t the two are equ ivalent :
Proposition 113 Let V and V' be categories. Let F and G be fun ctors
from V xV' to E. Suppose we are given a fun ction F( X , Y) ~ G(X, Y)
for each X E ob V and Y E ob V'. Then a is a natural transformation
from F to G iff
• a (X , Y) is natural in X E V for each Y E ob V'
• a (X , Y) is natural in Y E V' for each X E ob V .
D

Sometimes , however , we want to use t he idiom "na t ural in X and


Y" where X Y ranges over not a product category bu t an opGr cate-
gory. In that sit uation , we requi re t he following variant (in fact it is a
generalizat ion) of P rop. 113.
Representing Obj ects 263

Proposition 114 Let 1) be a locally C-indexed category, and let F


and G be functors from opGr 1) to E. Suppose we ar e given a function
FxY QXx. . Gx Y , for each X E ob C an d Y E ob 1). Then a is a
na tural transformation from F to G iff
• ax Y is natural in X E CoP for each Y E ob 1)
• a x Y is natural in Y E 1)x for each X E ob C.

F inally, we can adapt Prop. 113 and P rop. 114 to allow us to use the
idiom "a x (Y, Z ) is natural in X , Y and Z " .
Proposition 115 Let 1) and 1)' be locally C-indexed categories, and
let F and G be functors from opGr(1) x 1)') to E. Suppose we ar e given
a function Fx(Y , Z ) QX (r,~! Gx(Y , Z ), for each X E ob C, Y E ob 1)
and Z E ob 1)' . T hen a is a natural transformation from F to G iff
• a x (Y , Z) is na tural in X E CoP for each Y E ob 1) and Z E ob 1)'
• ax(Y , Z) is nat ural in Y E 1)x for each X E ob C and Z E ob 1)'
• a x (Y , Z) is natural in Z E 1)'x for each X E ob C and Y E ob 1).
D

11.2.2 Context Extension Functors


In type theory, t he op eration written as a comma in r , A is of great
importance and is often called con text extension . It is closely related to
the following functors , as we sha ll see in Sect . 11.3. Let C be a cartesian
category.
Firstly, we know t hat if X ' k • X and Y' f • Y, then we
can define a morphism X ' X Y' ~ X x Y. But suppose t hat, instead
of I , we have X' x Y' 9 • Y . Despite the extra dependency, we still
obtain a morphism X ' x Y' - - X x Y viz. ((7f;k),g) . We write k · 9
for t his morp hism, and . defines a funct or from opGr((self ct ) to COP,
given by x on obj ects. From this we can recover the usual functor x
Cop x Cop

q~
opGr((self Ct ) ~ Cop
264 CALL-BY-PUSH- VALUE

Here , the functor q takes (X, Y) to x Y and (k ,1) to k7r'* f. (We could
remove all these - op marks by using the Groth endieck construction rather
than opGrothendieck here.)
We make use of . in defining the following most important functor.
Definition 11.1 Let V be a locally C-indexed category, where C is
cartesian. We write growall for the functor
opGr((self C)OP x V) - - opGr V

x(Y, Z) f-I - ------+) xxyZ

k(J ,h) ----+)


If - kof 7r*h
Given a C-object A, we write growA , for the functor

op Gr V -opGr i
op Gr (1 x V) opGr(objA xV)
• op Gr (( se If C)OP x V) -growall op Gr V
Explicitly, this is given by
opGr V - opGr V

In the case that V = 1, it is evident that opGrV ~ Cop Modulo 0

this isomorphism, growall corresponds to cdot , and growA corresponds


to - x A . So we will sometimes write growA instead of - x A.
The following is often used in conj unct ion with context extension func-
tors.
r,

11.3 Representable Functors


11.3.1 Ordinary Category
Firstly, we recall from Sect . 9.3.2 the homset functor homv for an
ordinary category V .
We present our key definition [Mac Lane, 1971] in both element style
and naturality style.
Representing Objects 265

Definition 11.3 Let F : V ~ Set be a fun ctor . Let i : B ~ V be a


fully faithful fun ct or (it will be idv in many exa mples). A representing
object for F within i consists of a B-obj ect V (t he vertex) together with

element style an element v E Ft.V such t hat t he fun cti ons

V (iV ,X) ~ FX for all X


f r----7 (F J) v
are isomorphisms.
naturality style an isomorphism

V(iV, X) a: . FX natural in X.

We omit the phrase "wit hin i" when i = idv. o


The equivalence of these two definitions is essentially the Yoneda
Lemma:
Proposition 116 The naturality sty le and eleme nt sty le formulations
of Def. 11.3 ar e equivalent .
naturality to element style t he element v is a(iV )id.
element to naturality style t he isomorphism a is )..X.)..j. (F J) v.
o
By defining a categorical st ru ct ure to be a representing object , we
automatically obtain both an element style and na turali ty sty le des crip-
tion, and we know t hat they are equivalent . Here are examples, for the
st ruct ures we have seen so far.
Definition 11.4 Let C be a cartesian cate gory.
• A product for {BihEI is a representing obj ect for fl EI C_Bi.
• An expone n tial from A to B is a representing object for growzl; C_B.
• A exponen ti al-product for {(Ai, Bi) h EI is a representing obj ect for
I1 iEI (growAii C_Bi ) .
Let (C ,N ) be a JWA judgement model.
• A jumpwith for A is a represent ing obj ect for grow A jN.
• A coproduct-jumpwith for {Ad iEI is a representing object for
I1 iEI (growA i i N ).
266 CALL-BY-PUSH- VALUE

Let (C, 1),0) be a CBPV judgement model.


• A right adjunctive for B is a representing object for O _B.
• A right product-adjunctive for {BJiEI is a representing object for
TIi EIO_Bi'
• A right exponential-adjunctive from A to B is a representing object
for growA;O _B .
• A right exponential-product-adjunctive for {(Ai , B i) hEI is a repre-
senting object for TIi EI(growA i ;O_B i).
o
Notice, and this will be apparent throughout all our examples, how
the functor being represented is a description of the upper part of the
reversible derivation; it is a product, and each factor describes one of the
judgements above the double line . Each A on the left of the turnstile in
a judgement corresponds to growA in the corresponding factor.
When we define a categorical structure as a representing object of
a functor, we know that is unique up to unique isomorphism, in the
following sense.
Proposition 117 Let F be a functor from 1) to Set, and let ~ : B --+ 1)
be a fully faithful functor. Let (V, a) and (V' , a ') be naturality-style
representing obj ects for F within z. Then there is a unique isomorphism
V f . V' in B such that

commutes for all X.

If we write the representing objects in element style as (V, v) and (V' , v')
then f is characterized by (F~f)v = v'. 0

Proof This is proved the same way as Prop. 121 below; in fact it is a
special case. 0

11.3.2 Locally Indexed Category


Firstly, we recall from Sect. 9.3.5 the homset functor horn-n for an
locally C-indexed category 1) , where C is cartesian. We rep eat the defi-
nitions of Sect. 11.3.1 in the locally C-indexed setting.
Representing Objects 267

Definition 11.5 Let F : opGr 7) ----+ Set be a functor. Let" : B ----+ 7)


be a fully faithful fun ctor. A global representing obj ect for F within t.
consists of a B-object V (the vertex ) together with
n a turality style an isomorphism
ax Y
7)x("V ,Y) ",,- . FxY natural inXandY.

element style an element v E F I " V such that t he fun ctions

7)x("V , Y ) ----+ Fx Y for all X and Y


f 1-----7 ( FOJ) v

ar e isomorphisms.
o
P roposit io n 118 The naturality style and element style formulations
of Def. 11.5 are equivalent , and a global representing obj ect is unique
up to unique isomorphism. 0

Proof A global representing object for F within " can be seen as a


representing object for F within the composit e

(This is the reason for the "global" terminology.) o


Defin ition 11.6 Let (C , 7) , 0) be a CBPV judgement model.
• A left adj unct ive for a val-object A is a global representing object for
growA ; O.
• A left coproduc t-adj unc tive for {Ad iEI is a global representing obj ect
for ITiEI (growA i ;0) .
o
11.3.3 Cartesian Category
Let C be a cartesian category. So far , we have seen two homset fun c-
tors associa te d t hat C gives rise to :
• the fun ctor home obtained by regarding C as an ordinar y category,
ignoring its cartesian structure
• the functor homself e obtained by converting C into t he locally C-
ind exed category self C.
268 CALL-BY-PUSH- VALUE

But, in fact , there is a third homset functor hom xc sp ecial to carte sian
categori es:
opGr self C - Set

xY I ) CxY

X X'xY CxY 9

X' Y'
h I ) Ckh

Cx 'Y' (id,(k;g)) *h
I
This fun ctor provides all t he homset information we need . From it , we
can recover horn.;

opGr self C • Set


hom x c
where q is as in Sect. 11.2.2. And we can also recover homselfc
opGr( (self C)OP x self C)

growall (11.1)

opGr self C - - - --.. Set


hom x c

whe re growall is as in Sect. 11.2.2. As a consequence of (11.1) we have


self C_(A , -) = growA; hom xc (11.2)
and we make the following definition:
Definition 11.7 A distribut ive coproduct for a family of objects {A d iEI
in a carte sian category C is a representing obj ect for ITiEI (grow Ai; hom xc ).
D
Becau se of (11.2) , we can equivalently define a distributive copro duct to
be a locally indexed copro duct in self C [Ja cobs , 1999J. We prefer t he
for mulation of Def. 11.7, because it cont inues the pat tern that we noted
in Sect . 11.3.1: a connect ive is a representing obj ect for a fun ctor that
describes the upper line of its reversible derivation.
R epresenting Obj ects 269

11.3.4 Category With Right Modules


Ordinary Category With Right Modules
Suppose, as in Sect . 9.6.4, t hat we have a category V with a fam ily
of right V-modules {OP}PEP . Our aim is to make a homset functor t hat
describes each homset V (Y, Z ) as well as each homset OPZ.
Our first step is to "glue" t he modules to t he category in t he following
manner [Carbo ni et al., 1998]:

Definition 11.8 We write OeV for the category in which

• an objec t is eit her 'v . where PEP , or ky , where Y is an objec t of V

• a morphism ky - - --+. kZ is a V-morphism Y - - --+" Z

• a morphism c p - - --+-
. kZ is an OP-morphism - -- ---+-
. Z

• t he only morphism to cp is t he identity

• identi ties and compos it ion are defined as in V and t he various OP.

We write k_ for t he fully faithful fun ctor from V to OeV. o


Now we are in a pos it ion to define t he required homset functor.

Definition 11.9 We write hom° 'D for t he functor


",-,,",) Op k h
(O eV) OP XV (
~v X -: (O eV t X (O eV) om CJo1). Set

o
We can see tha t this achieves our goal, becau se

hom0 'D (ky, Z) V(y,Z)


hom° 'D(C p , Z) OPZ

Further more we have

(11.3)

We ca n use Def. 11.9 to t urn Def. 9.26 into naturali ty sty le.

Definition 11.10 Let V be a category and {OP}P EP a family of right


V-modules. A product for an object family { Bd iEI is a representing
object wit hin k_ for I1i E1 hom° 'D (- , B i ) . 0
270 CALL-BY-PUSH- VALUE

Locally Indexed Category With Right Modules


We now rep eat the above in the locally indexed setting. Suppose, as
in Sect. 9.6.4-9.6.5, that C is cartesian and we have a locally C-indexed
category V with a family of right V-modules {OP}P EP . Our aim is to
make a homset functor that describes each homset Vx(Y , Z) as well as
each homset O~ Z .
Our first step is to "glue" the modules to the category in the following
manner [Carboni et al., 1998]:
Definition 11.11 We write OeV for the locally C-indexed category in
which
• an obj ect is eit her 'v . where PEP, or ky, where Y is an object of V

x
• a morphism cp - - -+. kZ is an OP- morphism - - ---+
. Z
x X

• the only morphisms from cp are identities


• identities, composition and reindexing are defined as in V and OP.
We write k_ for the fully faithful functor from V to OeV. o
Now we are in a position to define the required homs et functor.
Definition 11.12 We write homov for the functor
k
opGr( (OeVt P x V) opGr((OoV)oP X _! opGr( (OeVtP x (OeV)) hom 001) • Set

o
We can see that this achieves our goal , because

hom~V(ky, Z)
hom~V(Cp, Z)

Furthermore we have

(11.4)

We can use this to adapt Def. 9.27 and Def. 9.28 to naturality style.
Definition 11.13 Let C be a cartesian category. Let V be a locally
C-indexed category (whose obj ects we underline) and {OP}P EP a family
of right V-modules.
Representing Objects 271

• A produ ct for a famil y of V-objects {Bih EJ is a global representing


object within k_ for TIiE Jhom ~1J ( - , B i ) .
• An exponen ti al from a C-object A to a V-obj ect B is a global repre-
sent ing obj ect within k _ for grow A ; hom ~1J ( - , B ).

• A expon en tial-produ ct for {(Ai, B iEJ is a global representing object


within k_ for TIiEJ(grow A i ; hom_ c3)}
1J (- , B )).
i
o

11.3.5 Cartesian Category With Left Modules


Now suppose, as in Sect . 9.6.6, t hat we have a cartesian category C
wit h a family of left modules N = {NP}PEP, We have already seen in
Sect . 11.3.3 a homset functor hom xc for C. But now we want to extend
t his to a homset fun ctor giving all t he homsets N~ as well as the homs ets
Cx Y .
To do t his, like in Sect . 11.3.4, we must first glue the modules to t he
category.
Definition 11.14 We wri te self cN for the locally C-indexed catego ry
in which
• an object is eit her vY, where Y E ob C, or :Up, where P EP

• a morphism vY - - --. vZ is a C-morphism X x Y Z


x - ---+
.

• a morphism vY - -- -. ' p is a NP -morphism X x Y


x - -- +

• t he only morphisms from 'par e t he identi ties


• t he identity over X on vY is tt'

f • vz 9
• the composite of vY
X X
• vW is (Jr, J) *g

f • vz 9
• the composite of vY
X X
• :Up is (Jr, J) *9

k f
• the reindexing along X ' • X of vy
X
• vz is (k xY) *j

k f
• t he reindexing along X' • X ofVY x • :Up is (kx Y)* j.

We wr ite v- for t he fully faithful fun ctor from self C to self CN. 0

Now we are in a positi on to define t he required homset fun ctor.


272 CALL-B Y-PUSH- VALUE

Definition 11.15 We wri te hom xCN for t he homset functor


opGr self CN - - Set

xY 1-
1 - ------+) C Y
X

~p If---- - -----t) Nr;


X X' xy Cx Y 9

k It 1-1 - - --t, C, h 1
x' y' Cx, y' (id,(k;g))*h

X X' xY Cx Y 9

k It (p) 1-1 - - - +, C,h 1


x' Nr;, (id,(k;g))* h
D

It is clear that t his achieves our goa l. Furthermore, t he diagram (11.1 )


can be generalized:
Proposition 119 The following diagram commutes
opGr ((V- lOP x)self CN)) P
opGr((self Ct x (selfCN)) • opGr(self CN x (selfCN))

growall hOmsell CN

hom x CN
opGr self cN - - - - -- - - - -- - ----+
. Set
and we write growhom x CN for t he composite of this. For each C-obj ect
A , we therefore have

growhom x CN _ (A , - ) homself o« _ (VA, - )


growA; hom xCN
D
Representing Objects 273

This enables us to write Def. 9.29 in naturality style:


Definition 11.16 Let C be a cartesian category and let {NP}P EP be a
family of left C-modules. A distributive coproduct for an object family
{Adi EI is a global representing object within v-for ITiEIgrowAi ; homxCN.
D

This completes our naturality style description of the connectives.

Proposition 120 Let V be the vertex of a distributive coproduct for


{Adi EI in a CBPV judgement model (C, D, O) -recall from Sect . 9.6.6
that this means a distributive coproduct in (C ,Nc + N k ) . Then the
associated isomorphism

hom ~~ v (Y , Z) ~ II hom~~ A i (Y , Z) natural in X


i EI
is natural also in Y and Z. D

Proof Immediate from the element-style description of this isomorphism,


viz. f f-7 Ai.((X x in.)" J) . D

11.4 Parametrized Representability


Note The results in this section are related to the Yoneda Lemma.
However, we omit this relationship, because it appears to be easier to
prove them directly than to derive them from the Yoneda Lemma. This
is especially true of Prop. 124.
We commonly wish to build functors out of representing objects. Sup-
pose , for example, that a category C has a product for each pair of objects
A and A' , whose vertex we write A x A'. We would like to make x into
a functor so that the isomorphism

C(X, A) x C(X, A') ~ C(X, A x A') natural in X

becomes natural in A and A'. There is a unique way of doing this, by a


theorem called "paramet rized representability" (the name is apparently
due to Hyland). We need such results for two purposes:
• to complete our definition of the possible world construction (Sect. 9.7.6)
• to compare different definitions of "adj unct ion", and proving Prop. 102.
Here is the basic theorem.
Proposition 121 Let F : J x D -----7 Set be a functor, and let t. : B -----7
D be a fully faithful functor. Suppose that for each I E J there is a
274 CALL-BY-PUSH- VALUE

representing object within i for F(I , - ), which we write in naturality


style as an isomorphism

D( iV(I) , X) Ct(~X( F(I , X ) natural in X.

Then V extends uniquely to a functor from J to BOP so as to make a(I , X)


natural in I as well as X .
If we write the representing object of F(I , - ) in element style as
(V(I) , VI ), then the functor V is characterized by
f
F( J, iV(j))VJ = F(j , iV(I))VI for I - -
A
-" J
o
Proof Sim ilar to t he proof of Prop. 122 below. 0
We adapt Prop . 121 to the locally indexed setting as follows.
Proposition 122 Let F : opGr(J x D ) --+ Set be a functor , and let
i : B --+ D be a fully faithful functor. Suppose that for each I E J
there is a global representing obj ect within i for F_(I, -) , written in
naturality sty le as an isomorphism

DX(iV(I) , Y) Ctx :,l::l Fx(I, Y) natural in X and Y.

Then V exte nds uniquely to a func tor from J to BOP so as to make


ax (I, Y) natural in I as well as X and Y .
If we write the representing object of F(I, - ) in element style as
(V (I), VI), then the fun ctor V is characterized by
f
(11.5)
o
Proof Using (11.5) it is easy but tedious to check that V is a func-
tor and that a is natural. We do t his by making diagrams of homset
operations, representing an element of a homset as a morphism from 1.
Conversely, suppose we have a functor V making a natural. T hen for
each -I A
f " -J we have
Representing Objects 275

Applying this to the identity over A on ~ V I gives (11.5) . D

Corollary 123 1 If (C,V , 0) is a CBPV judgement model with all left


adjunctives, then F extends to a unique functor self C F • V
making
Vx(F A , Y) ~ OX .A7r*Y
natural in A as well as X and Y.
2 If C is cartesian, V is a locally C-indexed category and {OPhEP a
family of right V-modules with all I-indexed products, then Di EI
extends to a unique functor VI D iE I I V making

hom:?1J(y, D iEIB i) ~ D iEI hom:?1J(y , B i)


natural in all {B i h EI as well as in X and Y .
3 If C is cartesian, V is a locally C-indexed category and {OPh EP a
family of right V-modules with all exponentials, then --+ extends to
a unique functor (self xV ct --+ . V making

hom:?1J(Y , A --+ B) ~ hom:?~(7r*Y,B)


natural in A and B as well as in X and Y.
4 If C is cartesian and N = {NPhEP is a family of left C-modules with
all I-indexed distributive coproducts, then I:iEI exte nds to a unique
functor self CI L self C making

(homxcN) x . I:i IAiY ~


E
II (homxcN)x .AiY
iE I

natural in {Ad iEI as well as in X and Y .


D

There is one more parametrized representability theorem that we re-


quire, involving the sp ecial homset functor for cartesian categories that
we defined in Sect. 11.3.3. Unfortunately, it does not appear to be a
special case of Prop. 121 or Prop. 122; it would be interesting to find a
common generalization of these results.
Proposition 124 Suppose F : opGr J --+ Set is a functor. Suppose
that for each I E J there is a representing object for F-L which we
write in naturality style as an isomorphism

_ ~
Cx V(I) "'" Fx _
I natural in X
276 CA LL-B Y-PUSH- VA LUE

Then V extends uniquely to a fun ctor from J to self C so as to make ax I


natural in I as well as in X .
If we wri te t he representi ng object of FI in eleme nt sty le as (V (I) , vI)
t hen the functor V is characterized by
f
(11.6)
A

o
P roof Using (11.6) , it is easy but tedious to check tha t V is a fun ct or
and that a is natural. Conversely, suppose we have a fun ctor V making
f
a natural. Then for each -I A • -J we have

Applyin g t his to t he identi ty on V I gives t he element-style cha racteri-


zation of V f. 0

Corollary 125 1 If C is a cartesian category with all I -indexed prod-


ucts, t hen TIiEI extends to a unique fun ct or self CI TI i EI. self C mak-
ing
Cx TI i EIBi ~ TIiEI Cx e,
natural in {Bil i Ef as well as in X.
2 If C is a cartes ian ca tegory with all exponentials, t hen -+ exte nds t o
a unique functor (self ct x C -t • C making

natural in A and B as well as in X.


3 If (C ,V , 0) is a CBP V judgement model with all right adj unct ives,
t hen U extends to a unique fun ct or V u . self C making

Cx UB ~ O x B

natural in B as well as in X .
R epresenting Objects 277

4 If (C ,N) is a JWA judgement model with all jumpwiths, then -,


extends to a unique fun ctor (self ct -=------ self C mak ing

natural in A as well as X.
o

11.5 Possible Worlds: Part 2


In Sect. 9.7.6 we built various locally C-indexed fun ctors between self C
a nd V. They restrict to fun ctors between self C1 and VI. Modulo the
isomorphism j from C to self C1 , these are fun ctors between C and V I ,
whi ch is what we require for possible worlds.
For the CBPV pos sible world const r uction, we define t he connect ives
at a morphism w 9 • x as follows.
u

IT(Wl ,J)EwjW(SW/ -+ B w') --.!!.. IT(xl,J)ExjW(Sx/ -+ E x')

such t hat h; 7f(x' ,J) = 7f(xl,(g ;J)) .


F

L(xl,J)ExjW(SX/ X Ax' ) --.!!.. L(W',J )EwjW(Sw/ X Aw')

such t hat in(x' ,J) ; h = in(x' ,(g;J)) .

• (L iEIAdg = L iEIA ig using CI L i El. C.

x
• (A X A')g is defined to be Ag x A'g using C x C - -_ . C.

• (ITiEIBi)g is defined t o be ITiEIBig using V[ ITi EI. VI .

• (A -+ B)g is defined to be Ag -+ Bg using Cop x VI ---=---- VI


For the JWA possible world const ruct ion, we define the connectives
at a morphism w 9 • x as follows.
278 CA LL-B Y-PUSH- VALUE

L (XI ,J)ExjW (S X' x Ax') --.!:... L (wl ,J)EwjW (S w' x Aw')

such t hat in(x' ,J);h = in(x' ,(gjJ)).

x
• (A x A')g is defined to be A g x A'g using C x C - - _ . C.
Defining all the homset operations in the possible world model and
proving that all t he required equat ions hold can be done by exp ressing
them as diagrams of homsets in the original model. We use all the natu-
ralities in Prop. 120, Cor. 123 and Cor. 125 together with t he equat ions

CjO*jg CU,g)
j· O*jg j xg

An alte rnative approach is to work in the term calc ulus , exploit ing our
kn owledge t hat all t he equations of CBPV + stacks are validated in a
CBPV adj unction mod el, and all t he equations of J WA are validated in
a J WA mo dule mod el.

11.6 Adjunctions and Monads


11.6.1 Definitions of Adjunction
Ordinary Adjunctions
Before we prove Prop . 102, we look at a variety of definitions of ad-
junction between ordinary categories, all of t hem equivalent to Def. 9.33.
Definition 11.17 Let B and V be categ ories . We underline obj ect s of
V.
1 An adjunction from B to V consists of
• two fun ctors

----
F
B •V
u
• an isomorphism

B (Y, U Z) 2::! V (FY, Z ) natural in Y and Z.

2 An adjunction from B to V consists of


Representing Objects 279

u
• a functor 1) • B
• for each Y E ob B, a representing object for B(Y, U -), whose
vertex we call FY.
3 An adjunction from B to 1) consists of
F
• a functor B • 1)
• for each Z E ob 1) a representing object for 1)(F-, Z), whose
vertex we call U Z .
4 An adjunction from B to 1) consists of

• two functions
F
ob B • ob 1)
u
• for each X E ob Band Z E ob 1) a bijection
B(Y, UZ) ~ 1)(FY, Z)
f
such that, for each B-morphism Y' - - ---. Y and each C-morphism
Z g . Z', the following commutes:

,
B(Y, UZ) ~ 1)(FY, Z)

BdY',UZ)
yY 0'
~
'0

1)(FY, Z')

1)(FY', Z) B(Y, UZ')

~..L <><t'
, "\lV ~0'
y

1)(FY', Z') ~ B(Y', UZ')

5 An adjunction from B to 1) consists of


• a (B,1))-bimodule i.e. a functor
M : BOP X 1) -t Set
280 CA LL-BY-PUSH- VALUE

• for each obj ect Z E V , a represent ing object for M (- , Z ), whose


ver tex we call U Z
• for each object Y E B, a representing object for M (Y, - ), whose
vertex we call FY .
D

We compare these defini tions as follows.


• In Def. 11.17(1)-like in Def. 9.33-both F and U are given on both
objects and morphisms. Accordingly, the isomorphism

B(Y, UZ ) ~ V(FY, Z) (11.7)

is required to be natural in both Y and Z.


• In Def. 11.17(2) , U is given on both obj ects and morphisms but F
is given only on obj ects. Accordingly, the isomorphism (11.7) is re-
quired to be natural in Z bu t not in Y.
• In Def. 11.17(3), F is given on both objects and morphisms but U
is given only on objects. Accordingly, t he isomorphism (11.7) is re-
quired to be natural in Y but not in Z.
• in Def. 11.17(4)- (5), both U and F are given only on objects. Ac-
cord ingly, in Def. 11.17(4) t he isomorphism (11.7) is not req uired to
be natural in either Y or Z , while in Def. 11.17(5), it is di vid ed into
two isomorphism s:
B(Y, UZ ) ~ M (Y, Z ) natural in Y
M(Y, Z ) ~ V (FY, Z) natural in Z

Proposition 126 Def. 11.17( 1)- (5) and Def. 9.33 are all equivalent . D

Proof The equivalen ce of Def.9.33) and Def. 11.17(1) is standard. The


equivalence of (1)-(3) and (5) is a consequence of param etrized repre-
sentability (Prop. 121). In moving from (1) to (5) we can either set
M(Y, Z) to be B(Y, UZ) or we can set it to be V(FY, Z). The equiva-
lence of (4) and (5) is straightfo rward. D

Locally Indexed Adjunctions


Each of t hese defini tions ca n be adapted to locall y C-ind exed adj unc-
t ions .
Definition 11.18 (cf.l 1.17) Let B and V be locally C-indexed cate-
gories . We underline obj ects of V .
R epresenting Objects 281

1 An adjun ction from B to D consists of

• two fun ctors


F
B - -- -· D
u

• a bijection

BdY, U Z) ~ D dFY, Z) natural in r ,Y and Z.

Note In the lit erature, the condit ion of naturality in I' is usually
replaced by the B eck-Ch evalley condition . The two conditions
ar e equivalent (assuming naturality in Y and Z) , but we use the
former because we consider it to be mor e intuitive.

2 An adjunction from B to D consist s of

• for each Y E ob B, a representing object for B_(Y, U -) , whose


vertex we call F Y .

3 An adjunction from B to D consists of

• for each Z E ob D a representing obj ect for D _(F - , Z) , whose


vertex we call U Z .

4 An adjunction from B to D consist s of

• two func tions


F
ob B • ob D
u

• for each Y E ob B and Z E ob D a bijecti on

Bx (Y, U Z ) ~ Dx (FY, Z ) na tural in X


282 CALL-BY-PUSH- VALUE

such that , for each B-m orphism Y' - -- -. Y and each C-morphism
9
x

Bx(Y' , UZ)

Vx(FY' , Z) Bx(Y, UZ')

'
' 'r~--1-
<;' t'
0'
~..J ~+
V x (FY' , _
Z')~Bx (Y' ,U_
Z')

5 An adjunction from B to V consists of

• a (B,V)-bimodule i.e. a functor


oP
M : opGr(B x V) ---+ Set

• for each object Z E V , a representing object for M - (- , Z) , whose


vertex we call U Z
• for each obj ect Y E B, a representing object for M _ (Y, -) , whose
vertex we call FY .

Strong Adjunctions
We now prove Prop. 102, using Def. 11.18(2) to define adjunction
between self C and V.
Proo] Given a strong adj unction from C to V , we const ruct U as in
Cor . 125(3). Given a C-obje ct A , we construct an isomorphism

V x(FA , Y) ~ self Cx(A ,Y) natural in X and Y


R epresenting Obj ects 283

as t he composite
opGr U
opGr 'D • opGr self C

'D _ (FA , - )
~ opGr U
opGr 'D -
;:/
opGr self C self C_ ( A ,- )

Se t = == Se t = = = = Se t = = = = Se t

The right trapezium commutes by Prop. 119.


Conversely, given a n adj unct ion in t he sense of Def. 11.18(2) from
self C to V , define 0 to be opGr U ; home . This immediately gives the
required struct ure .
It is clear that t hese two t ransformations are inverse up to isomor-
phism . 0

11.6.2 Terminality of Eilenberg-Moore


In Sect . 9.7.2 we saw t hat, given a st rong monad (T , n, p" t) on a carte-
sian category C, we can const ruct a strong adj unction of T -algebras and
algebra homomorphisms. We write EM(T ) for this strong adj unction; it
has t he following prop er ties.

P roposition 127 1 Let (T , 'fl, p" t ) be a st rong mona d on C. Then


EM(T ) is a resolu ti on of it .

2 Let (C, V , 0) be a st rong adj unction. Write (T, 'fl, p" t ) for t he strong
monad it gives rise to .

• There is a uniqu e comparison functor K (in the sense of Sect . 9.6.8)


from (C, V , V) to EM(T ). It takes
a V-object Y to the algebra whose carrier is UY and whose
structure map is
Ul y
-----=-
~
U F UY -----=.. 1 x U F UY UY
h
X
9
an V-morphism
x
phism X - -- -... U Z .
284 CALL-BY-PUSH- VALUE

Therefore EM (T) is terminal in the category of resolutions for


(T, "7, J-L, t).
• Any distributive coproduct in (V,O) of {Aih EI is mapped by K
to a distributive coproduct in EM (T) of {Adi EJ.
• Any product in (V,O) of {BdiEI is mapped by K to a product
in EM(T) of {KBih EI.
• Any exponential in (V,O) from A to B is mapped by K to an
exponential in EM(T) from A to KB.
o
Proof This is straightforward if we assume, without loss of generality by
Prop. 101, that the U isomorphism

is the identity. 0
It follows from this that if (V, 0) is a CBPV adjunction model, then
EM(T) will have all countable distributive coproducts, and it will have
all finite products of comp-objects by Prop. 103(2). If all idempotents
split in C, then Cor. 105 tells us that EM(T) must be a CBPV adjunction
model. Otherwise, it might not be .

11.6.3 Kleisli and Co-Kleisli Adjunctions


Ordinary And Locally Indexed Adjunctions
Definition 11.19 An (ordinary or locally C-indexed) adjunction
(B , V, M, U, F) is Kleisli iff ob B = ob V and the left adjoint F is
identity-on-objects. It is co-Kleisli iff ob B = ob V and the right adjoint
U is identity-on-objects. 0

Proposition 128 A Kleisli (co-Kleisli) adjunction is initial in the cate-


gory of resolutions for its monad (comonad), and all comparison functors
from it are fully faithful. Furthermore, every monad (comonad) has a
Kleisli (co-Kleisli) resolution. 0

This is standard e.g. [Mac Lane, 1971].

Definition 11.20 Let (B, V, M, U, F) be an (ordinary or locally C-


indexed) adjunction in the manner of Def. 11.17(5) or Def. 11.18(5) .
We define its Kleisli part (B , V/, M', U/, F') to be the Kleisli adjunction
Representing Objects 285

given by

ob V' ob B
V'( A ,B) V(F A , F B)
M' (A , B ) = M (A , F B )
F 'A A
U'B UFB
with its identities, composit ion, isomorphisms etc. all inheri ted from
(B , V , M , U, F) . Dually, we define its co-Kl eisli part (B' , V , M ' , U' , F ')
to the co-Kleisli adjunction given by

ob B' ob V
B'(G, D ) B(UG, UD )
M '(G ,D) = M(UG,D)
U'D D
F'G FUG
with all structure inherited. o
Proposition 129 An adj unction (B, V, M , U, F) and its Kleisli part
(C, V , M , U', F ' ) give rise to t he same monad. The unique compari-
son functor is given by F on objects, and t he identity on morp hisms.
Similarly for the co-Kleisli part. 0

Given an adjunction (B, V , M , U, F) we thus obtain the following di-


agram show ing the Kleisli and co-Kl eisli parts, and their embeddings.
F

B[_," ,
,
1-
u ,
, "
>~ V
Kleisli I- '~~' -1 co-K leisli
, ,
, ,
, ,
, ,
K ' '0 £

Strong Adjunctions
We shall see that the notions of Kleisli adjunction, co-Kleisli adjunc-
tion and Kleisli part apply straightforwardly to strong adjunctions, but
not the notion of co-K leisli part.
Definition 11.21 1 A strong adj unction (C, V , 0 , U, F) from C to V
is Kl eisli iff ob C = ob V and t he left adjoint F is ident ity-on-objects.
286 CALL-BY-PUSH- VALUE

It is co-Kleisli iff ob C = ob V and the right adjoint U is identity-on-


objects.
2 Let (C, V, 0, U, F) be a strong adjunction. We define its Kl eisli part
(C ,V' , 0' , U', F') to be the Kleisli strong adjunction given by
ob V' ob C
V~(B ,C) VA(FB ,FC)
O~B OAFB
F'A A
U'E UFB
with identities, composition, reindexing, isomorphisms etc . inherited
from (C,V , 0 , U, F).
D
These agree with the corresponding notions for locally indexed ad-
junctions.
Proposition 130 1 A strong adjunction from C is Kleisli (resp. co-
Kleisli) if the corresponding strong adjunction from self C is Kleisli
(resp. co-Kleisli).
2 If the strong adjunction (C ,V , 0) corresponds to the locally C-indexed
adjunction (self C, V , M) then their Kleisli parts correspond too.
D

But in the co-Kleisli part (B', V , M') of an adjunction (self C, V , M) ,


the category B' is not of the form self C', and so this part does not
correspond to a strong adjunction. We therefore must define the co-
Kleisli part of a strong adjunction somewhat differently.
Definition 11.22 Let (C ,V , 0 , U, F) be a strong adjunction, where
V-and hence (V,O) by Prop. 97-has finite products. We define the
co-K leisli part of this strong adjunction to be the co-Kleisli strong ad-
junction (C' ,V' , 0' , U' , F') given by
ob C' ob V
C'11-E CUAUE
V A(B , C) V UA(E, C)
0'A-B OUAB
U'E B
F'A FUA
with the cartesian structure on C' given by the finit e products on V, and
all structure inherited. D
Representing Objects 287

11.6.4 CBV Is Kleisli, CBN Is Co-Kleisli


We recall t hat t he translation of a CBV term into CBPV always has
t he form r I- c M : FA . So, in a given CB PV model, it denotes an
O-m orphi sm 9 over [r] to F[A] , whi ch lies in t he Kl eisli part .
On t he ot her hand , t he t ranslation of a CBN te rm into CBPV always
has t he form U A o, " " U A n - 1 I- c M : B. In a given CBPV mo del, it
denotes an O- morphism 9 over U [A o] x ... x U[A n _ 1 ] to [B ]' Using t he
isomorphism U A x U AI ~ U(A n AI), this morphism 9 corresponds to a
morphism glover U[1] to [B] , where we write [I] for [A o]n - .. n [An-I].
T his morphism gl lies in t he co-K leisli part .
T his suggests t hat we can form ulate categorical semantics for CBV
and CBN by trying to characterize t he Kleisli part and the co-Kleisli
par t of a CBPV adj unction model. Of course, to see how these are
genuine ly suitable for CBV and CBN, we would have to introduce stack
terms j ust as we did for CBPV.
Definition 11.23 A (A-setjcppo jdomain enriched) CBV adjunction
mod el is a (A-setjcppojdomain enr iched ) CBPV j udgement model
(C , V , 0) whe re V and C have the same objects (which we do not under-
line) , equipped with
• a left adj unctive for each object A , whose vertex is A
• all countable I right expo nential-product-adjunctives, whose vertex
we write as Il~I Ai Bi
• all counta ble distrib ut ive coproducts.
o
In such a model, the distrib ut ive coproducts model sum types in CBV,
while the countable right exponential-product-adj unctives model a less
fami liar connective, a special case of t he general funct ion type considered
in Sect . A.1.3. Briefly, Il ~ I Ai Bi is a type in which a value is a A-
abstraction t hat takes two operands-a tag i E I and a value of typ e
Ai-and returns a value of type Bi.
Definition 11.24 A (A-setjcppojdomain enr iched ) CBN adjunction
mod el is a (A-setjcppojdomain enr iched ) CBPV j udgement model
(C,V , 0) where V and C have the same obj ects (which we underline) ,
equipped with

1 If we are modelling finit ely wide synt ax only, it suffices to require all right ex ponent ial-
adjunctives, as in [Levy et al., 2003J. This automaticall y gives us all finite rig ht expone nt ial-
prod uct- adj uncti ves, usin g th e finit e products in C.
288 CALL-B Y-PUSH- VALUE

• a right adj unct ive for each obj ect A , whose ver tex is A
• all count able left copro duct-adj unct ives, whose vertex we wri te as
L iE/Ai
• all countable products and exponentials.
o
In such a mod el, the left copro duct-adj unct ives model sum types in CB N.
We now see that the Kleisli and co-Kleisli parts of a CBPV model do
ind eed have these st ru ct ures .
Proposition 131 1 A CBV adjunction model is a Kleisli strong ad-
junction. The Kleisli part of any (A-set/cppo/domain enriched)
CBPV adjunction model (C , D, G) is a (A-s et/cppo/domain enr iched )
CBV adjunction model.
2 A CBN adjunction model is a co-Kleisli st rong adj unct ion . The
co-Kleisli part of any (A-set/cppo/domain enr iched ) CBPV adjunc-
tion model (C , D, G) -which is well defined because D must have
finit e products-is a (A-set/cppo/domain enr iched) CB N adj unct ion
mod el.
o
This is summarized by t he slogan "CBV is Kleisli, CBN is co-Kleisli" .
A spec ial case is where t he CBP V adjunction model is a cont inuation
mod el, obtained from t he JWA module model (C ,N) . In this case,
• t he denotation of a CBV term is a N-morphism from [r] x .[A]
• t he denotation of a CB N term is a N-morphism from -,[I] x [B ].
This is described in [Streicher and Reus, 1998] as "duality between CBV
and CB N, with control ope rators" , and the theme is further developed
in [Curien and Herb elin, 2000; Selinger , 2001; Wadler , 2003]. It is a
consequence of the duality between valu es and stacks, and between F
and U, in a continuation model.

Families Constructions From CRV And CRN Models


Given a CB N model or CBV mod el, it is possible to construct a CBPV
model using an appropria te families const ruction, as we now see. We
treat t he CBN case first [Abram sky and McCu sker , 1998], as it is simpler
and more common. The idea is t hat , since every value ty pe in CBP V
is isomorphic to one of t he form L iE/ U B i , we can simulate a val-object
as a family of comp-objects.
R epresenting Objects 289

Definition 11.25 Let (C,V , 0) be a (A-s et/cppo/domain enr iched) CBN


adj unction model. We define a (A-set/cpp o/domain enr iched) CBP V
adj unction model (C' ,V' , 0') as follows.
• A val-obj ect is a countable family {A h El of objects of t he CBN
model- to be t hought of as L iElUA i .
• A comp-object is an object B of the CBN model.
The homsets ar e given by

C'{A;}iEI {B
- j }-
] EJ III:CAiB j
iEl j EJ
tr.{A;}iEI (B
- , -C) II V Ai(B , C)
iEI
O{ A;}iEI B = II
iEI
O AiB j

with the evident identi ti es, composit ion and reindexing. The connectives
are given by

1 {1}
{ A i h El x {B j h EJ { A i x B j }c i ,j )El XJ
L iEl { A ij }j EJi {Aij} (i,j )E L iElJi
{AJ i El -t B ITiEl (A i -t B )
UB {B}
F { A i h El L iElAi
and comp-object product s as in t he CBN model. o
Clearly the co-Kleisli part of such a CBPV model is isomorphic to our
original CBN adjunction mod el.
The predomain/domain CBPV model is an instance of this construc-
tion , because we defined a predomain to be any cpo that is a countable
disjoint union of domains. This construction is used also in [Abramsky
and McCusker, 1998J to build Q/ A-lab elled pointer games. Indeed , given
a CBP V pre-families model, we can first obtain a CBN adj unction model
and t hen a CBPV adjunction model, and t his compos it e construction is
t he same as Def. 9.4l.
T he construction from a CBV model is more complicated. The idea
is t hat, since every computation ty pe in CBP V is isomorphic to one
of the form ITiEl (A i -t F Bi)- alb eit not uniquely-we can simulate a
comp-object as a family of pairs of val-obj ects.
290 CALL-BY-PUSH- VALUE

D efinition 11.26 Let (C , 1), 0) be a (A-set/cppo/domain enriched) CBV


adjunction model. We define a (A-s et/cppo/domain enr iched ) CBPV
adjunction model (C' , 1)' , 0') as follows.
• A val-object is an object A of t he CBV model.

• A comp-object is a countable family {(Ai , B d iEf of pairs of objects


of the CBV mod el-to be thought of as TIiEf (Ai -+ FBi)'
The homsets arc given by

C~B CAB
1)~ ({ in.;Cd h Ef, {(Dj , Ej)} j EJ) II :L) CA XDj B i x 1)A x Dj ic; E j )
j EJ iEI
II O A XDj E j
j EJ
with the obvious identi t ies, composit ion and reind exing. The connectives
ar e given by

A -+ {(B j , C j)}jEJ {(A x B j , Cj)} j EJ


TIiEf {(Bij , Cij)} jEJi {( B ij , C ij)} (i,j )E L iEIJi
U {(Bi, Ci )}iEI { TI~IBiCi}
FA {(I , A)}
Products and distributive copro duct s of val-objects ar e as in the CBV
~~. 0

Clearly the Kleisli part of this CBPV model is isomorphic to our original
CBV adj unction model.
IV

CONCLUSIONS
Chapter 12

CONCLUSIONS, COMPARISONS AND FURTHER


WORK

12.1 Summary of Achievements and Drawbacks


In Part I, we introduced the CBPV paradigm as a language of seman-
tic primitives for higher order programming with computational effects
(even just divergence). In Part II we saw a vast range of semantics that
support CBPV's claim to be such a language , subsuming both CBV
and CBN. That range includes models for printing, storage , divergence,
errat ic choice, errors and control effects ; it also includes possible world
models and interaction-based semantics such as jumping (using continu-
ation semantics) and pointer game models. Again and again, we saw the
advantages of using CBPV as a language of study. For example, in the
int eraction-based semantics, t he explicit control flow in CBPV makes it
closer to the detailed behaviour present in the model than CBN or CBV
ar e.
However , there were some examples of CBV models that we were
unable to decompose into CBPV in a natural way:

• the model for input based on Moggi's input monad [Moggi, 1991]

• the constrained model for finite erratic choice based on the strong
monad Pfin on Set, described in Sect. 5.5.3;

• the const rained model for store that incorporates parametricity in


initializations, mentioned in Sect. 6.9.

But see Sect. 12.2 for further remarks on this.


In Part III, we saw that all of our semantics for CBPV are instances
of adjunction models. It is therefore reasonable to say that what CBPV
achieves is to decompose Moggi's strong monads into st rong adjunctions.

293
P B Levy, Call-By-Push-Value
© Springer Science+Business Media Dordrecht 2003
294 CALL-BY-PUSH- VALUE

In the P hD version of t his monograph , t hat claim was problematic be-


cause of t he absence of stack terms. However , it has now been validated
through our incorporation of stacks into the equational theory.

12.2 Simplifying Algebra Semantics


W hilst we said that the CBV models for finite erratic choice and inp ut
do not have a natural CBPV decompos it ion, recent work of [Plotkin and
Power , 2002] suggests a more optim istic concl usio n. For many effects ,
including t hese two , the relevant strong monad on Set (and, sometimes ,
on other categories too) can be presented using algebraic operations and
equations ; and t his leads to a simple characterization of algebras. Thus,
for t hese effects, t he algebra semantics for CBPV appears more natural
in t he light of this research t han it did previously.

12.3 Advantages Of CBPV Over Monad And


Linear Logic Decompositions
We contrast t he success of the CBPV decompositions of CBV and
CBN type constructors with 2 ot her well-known decomposit ions:
• Moggi's decomposit ion of A -rCBV B as A -r T B by contrast wit h
our U(A -r FB)
• the linear logic decomposition of A -rCBN B as !A -0 B by contrast
with our (U A) -r B.
Both these decompositions/translations are given in [Benton and Wadler,
1996].
For discussion's sake , we will say that the types of Moggi's target
la nguage incl ude
A ::= bool I nat I A x A I A -r A I TA I ...
although Moggi does not exp licit ly include bool and nat . In categorical
terms, Moggi's decomposition of -rCBV is isomo rp hic to ours, because
U(A -r FE ) must be t he vertex of an exponent from A to TB . But
much is lost in Moggi's translation, as we now explain .
• As we sai d in Sect . 1.2.3, the mona dic language does not have an
operationa l semantics (at least not a simple one in t he same way as
CBV, CBN and CBPV) because it is a language of values .
• Although t he monadic language does have a denotational semant ics
using cpos, in which A -r B denotes the cpo of total functions from
[A] to [B] , this is not a pr edomain semantics (Def. 4.8). For ex-
ample, nat -r nat denotes an uncountable flat cpo , which is not a
predomain .
Conclusions, Comparisons and Further Work 295

• We cannot add general type recursion to the monadic language, be-


cause for example we could not interpret j.LX .(X -+ bool)-there is
no cpo X such that X ~ X -+ 2. The usual technology for re-
cursively defined cpos (Sect. 4.3.2-4.3.3) is not applicable, because
-+ does not give a mixed variance, locally continuous functor on a
bilimit-compact category.
• We cannot translate the monadic language into J ump-With-Argument
(preserving semantics), so we do not have a jumping implementation
for it . To put this another way, look at the continuation semantics
for A -+CBV B given by the two decompositions:
A -+ T B gives A -+ -,-,B
U(A -+ F B) gives -,(A x -,B)

These are isomorphic. But the latter is meaningful in a jumping


sense-it says that a CBV function is a point to which we jump
taking both an argument and a return address for the result. By
contrast, the -+ used in the former cannot be understood in jumping
terms.
• For possible world semantics, we saw in Sect. 6.6.4 that A -+CBV B
has a simple and intuitive possible world semantics
[A --+CBV B]w = II (5w' --+ [A]w' --+ L (5w" x [B]w")) (12.1)
w/ ~w w1/~w'

But if we use monadic decomposition of -+CBV , we must recall how


to calculate an exponential in a functor category as an end

(A -+ B)w = r
i.:
(Aw' -+ Bw')

and we then obtain the following :

[A --+CBV B]w = 1w '~ w


(Aw' --+ II
W "~ W '
(5w" --+ L
w /l '~w"
(5w'" x [B]w" ')))

This is isomorphic to (12.1) -although the isomorphism is hardly


obvious-but it is unintuitive and more complicated. Calculations
using it will be more difficult.
The target language of the linear logic decomposition is a linear A-
calculus with types including

(We are underlining the types because they denote pointed cpos.)
296 CALL-BY-PUSH- VA LUE

Much is lost in t he translation from CBN into t his lan guage. For
exa mple, O'He arn's sem an tics of global store

[A -t C B N B ] = (8 -t [A] ) -t [B ]
an d t he Streicher-Reu s conti nuation semantics

[A -t C B N B] = (---,[A]) x [B ]
do not exhibit the linear decomposition. On e reason for this is that , as
we said in Sect . 1.2.3, t he linear A-calculus ass umes commutat ivity of
effects .
For t he same reason, t he pointer game mod el for CB N (given by the
CBPV model of Ch ap. 8) does not exhibit the linear decomposition of
-tC B N . This is perhaps sur prising, given the influence of linear logic on
t he development of game semantics.

12.4 Beyond Simple Types


In t his book we have st udied only simply ty pe d lan guages, toget her
with recursive and infini tary ty pes. We have not looked at polymorphism
or dep endent typing.

12.4.1 Dependent Types


Dep endent types and computationa l effects are a problematic combi-
nation, as Moggi found.
On t he one hand, it is easy and even be neficial to add dependent
ty pes to CBPV. We ca n generalize x to a dep endent sum connective,
and generalize -t to a dep end ent product connective. The one typing
rul e t hat requires care is t he sequencing rule
r f-c M : FAr , x : A f-c N : 11
r f-c M to x. N : B
In this rule, we must st ipulate that B does not dep end on x, only on r.
This restriction is indisp ens abl e if we want to ret ain our denotational
mod els. The categori cal semantics of this language rem ain to be studied ,
bu t we do not expect difficulti es. And we can likewise exte nd JWA,
generalizing x to a dep endent sum connect ive.
Bu t t he problem: t here is no obvious t ranslation from A-calculus with
dep endent sums and dep endent product s into t his "depe nde nt ly ty ped
CBPV" . In t he simp ly ty ped case we have 2 t ranslations (CBV and
CBN); but t he CBV t ranslation of application and t he CBN translation
of pat tern-ma tching both use sequencing, and when we t ry extend to
t he depende nt ly ty ped setting, we violate t he a bove rest riction .
Conclusions , Comparisons and Furth er Work 297

Thus it appears that this "dependently typed CBPV" may not be as


expressive as a dep endently typed language without effects .

12.4.2 Polymorphism
From an ope rational perspective, we sp ecul ate that we could add poly-
morphism to CBPV by adding the following type construc tors:

A··= I X I L:X.A I L:X .A


B ··= I X I nX.B I nX.B
In the sam e way, we could add polymorphism to JWA by adding the
following typ e const ructors

A ..= ... I X I L:X.A

However , whether these exte nsions are operationally and denotation-


ally well-b ehaved remains to be investigated.

12.5 Further Work


In addit ion to the investigation of dep endent and pol ymorphic types
mentioned above, t here ar e a number of holes in various places in the
book that need to be filled , and the problems involved are by no means
trivial.
• Providing complex values and an equati onal theory in the setting of
infinitely deep synt ax .
• Development of models combining errat ic choice and divergence (in-
cluding the new may-testing model of Sect . 5.5.4).
• Development of parametric mod els for cell generat ion.
• Prove that the pointer game model of JWA does indeed describe the
set of possible t races of a term according to the jumping op erational
semantics.
• In relating syntax t o cate gorical semantics (Chap. 10), allow the ob-
ject structure to vary.
Appendix A
Technical Treatment of CBV and CBN
300 CALL-BY-PUSH- VALUE

A.I The Jumbo A-Calculus


A.I.I Introduction
This chapter looks in detail at the relationship between CBV, CBN and CBPV.
We will prove various technical results, including universality and full abstraction of
transforms. The various languages, translations and results are listed in Sect. A.2 .
Before we come to these, it is helpful to recollect what we were aiming to achieve
in Chap. 1-2:
We take a purely functional language, add a computational effect (e.g.
printing) and explore various possible choices: about evaluation order, about
observational equivalence etc. Then we seek a single language that includes
all of these possible choices.
The wider the range of language possibilities that we explore and show to be included
within CBPV, the stronger our claim that CBPV is a "subsum ing paradigm" .
In this chapter we car efully retread this path. In order that our exploration of pos-
sibilities be as thorough as possible, we want our starting point (the purely functional
language) to have a wider range of type constructors than was provided in A bool+.
For example, we want to look at product types. Rather than decide a priori
whether these will be projection products or pattern-match products (in the sense of
Sect. 1.3.2) , we will provide both. We will then see how each is affected by the addition
of computational effects , and eventually verify that each possibility is included within
CBPV.
Similarly, we will provide not just unary but multi-ary functions. For although
there are various isomorphisms that justify the decomposition of multi-ary function
types into unary function types, it is not clear a priori that these will continue to be
valid when effects are added.
The purely functional language that we use is called the jumbo A-calculus. Because
it is intended as an exploratory tool, as we have explained, it has extremely general
jumbo connectives
tuple types include both sums and pattern-match products as special cases.
function types include both unary function types and projection products as spe-
cial cases.
We work with infinitely wid e languages (see Sect. 4.1 for a discussion) . The reader
wishing to consider only finitely wide languages should substitute "finite" for "count-
able" throughout this chapter.

A.I.2 Tuple Types


Tuple types are "sum of product" types in usual programming parlance. Something
of tuple type is formed as a finite tuple consisting of a tag and several terms; the
number of terms and their types depend on the tag. This is the most liberal tuple type
formation possible within a simply typed language, because simple typing requires
that the type of a term cannot depend on the type of another term, only on a tag.

Definition A.I A hyper-arity is a countable family of natural numbers {rd iEI . D

Let {ri}; EI be a hyper-arity. We define the tuple connective for this hyper-
arity as follows . Suppose that for each i E I we have a finite sequence of types
L..iEIE$ r i A i i . ThIS
AiO , .. . , A i (ri- I ) ' Then we form the tuple type ",Xj . d enotes t h e set
APPENDIX A : Technical Treatment of CBV and CBN 301

:LiE/ ([Ai O] x . .. X [Ai (r. -1) ]), or, isomorphically, t he set of t uples (i , ao,·· · , ari-d ,
wh ere aj E [A i j l
When eac h r i = 1 t his con nective is t he usual sum :LiE/ Ai. In par t icular, wh en
I = {O, I} we obtain t he binary sum A + B and wh en I is empty we obtain t he zero
type O.
When I is a sing leton set {*} and r , = 2, we obtain a pat t ern- mat ch binar y
product ty pe A x B . Sim ilar ly, when I is a singleton set {*} and r; = 0, we obtain
t he patt ern-m atch-unit ty pe 1.
In t he effect -free setting , :L, x and 1 are sufficient to give all t uple ty pes b ecau se
of t his decomposit ion :

", Xi ESri A i j =
L.JiE/ L.JiE/ (A i O X
~ '"
" ' X
A
i (ri- )
I) (A. I)

However , it is not apparent a priori wh ether (A.I ) will remain valid when we add
effects. This is the reason for providing general t u ple ty pe s. (In fact , (A.1) is valid in
C BV bu t not in CBN .)
An other spec ial case of t uple typ es is when eac h r i = O. Such a t uple typ e is
called a ground type. Its closed te rms are of t he form (i) , for i E I; sometimes we
wri t e t his just as i. In par ticular whe n I = {true, false} we call this ty pe bool and
when I = N we ca ll t his ty pe nat . We wri t e true for (t rue) , false for (fa lse) and
i f M then N else N ' for pm M as {(true). N , (fa lse) . N'} .

A.1.3 Function Types


Jumbo A-calculus functi on ty pes are a gene ralization of t he usual u nary fun cti on
ty pes . Something of un ar y fun ct ion ty pe is applied to a single op erand. By cont rast,
some t hing of jumbo A-calculus fun cti on ty pe is applied to several ope rands . The
first ope rand is a tag and t he rest are terms. The number of t erms and their ty pes
depend on t he t ag , a nd t he ty pe of t he result also dep ends on t he tag. This is t he
mo st lib eral function ty pe formati on possible within a sim ply ty pe d lan gu age, becau se
sim ple ty ping requires t hat t he type of a te rm ca nnot dep end on t he ty pe of an other
te r m , only on a tag.
We use a novel not at ion : wh en we apply a fun ction to several operands, we delimi t
t hes e operands on t he left with t he symbol L. For example N applied to Mi, and
M I is written LMo, M I 'N . The reason we do not write it (Mo , M d 'N is t hat t his
not ati on suggests t hat (Mo , MJ) is a su bterm , wh ich it is not .
Let {ri hE! be a hyp er- ari ty. We define t he function conn ective for this hyp er-
arity as follows. Su ppose that for each i E I we have a finite sequence of ty pes
A i O, . . . , A i (r. - I) and another type B i, T he n we form t he fun ction type IT ~~E S ri A ij B i,
This denotes t he set ITiE/([AiO] -+ ... -+ [A i (ri- 1}] -+ [Bi]) , or isomorphically
t he set of fun ct ion s t hat takes t he sequence of operands Li , ao, . . . ,ari- I, wh ere
«s E [Ai j ], to an element of [Bil
W here each r , = 1 we obtain a proj ection product ty pe wri t t en ITiE/A i. In
par t icul ar , whe n I = {O, I} we obtain t he binary pr oj ect ion-product whi ch we wr ite
An B , an d when I is empty we obtain t he proj ecti on-unit I n.
W hen I is a sing leton set , say {*}, an d r; = 1 we obtain t he usual unary fu nction
ty pe A -+ B .
In t he effect -free setting IT and -+ are sufficient to give all fun cti on ty pes becau se
of this decompositi on :
--+iESri A i j B i =
IT iE/ ~ IT iE/ (A i O -+ . . . -+ A i (ri- I) -+ B i ) (A .2)
302 CALL-BY-PUSH- VALUE

However , it is not apparent a priori whe ther (A .2) will rem ain valid when we add
effects . T his is t he reason for providing general function ty pes . (In fact , (A.2) is valid
in CBN bu t not in CBV.)

" , X j E $r 'A
Types A ::= L.J i EI 1 ij

where each set I is countable.

T erms

r f- M : A r ,x : A f- N : B

r , x: A, r ' f- x : A r f- let M be x . N : B

r f- M o : A i O ... r f- M r, - I : Ai(r, -I)

r f- (
A

l, M o, . . . ,Mri - I :
) ", X j E $r i
LJ i E/
A ij

A ... r ,xo : A i O, ... , X ri - I


r f- M :
", X j E $r '
LJ i E/ • ij : A i (ri- I ) f- Ni : B . . . iE /

r f- pm M as {... , (i, xo, ... , Xri - I).N i , ... } : B

r, xo: Ai 0, ·· · , Xri-I : A i ri -I f- M; : B , .. . iE/

r L '{ . . . ,
IA L 'Z' , xo, . . . , Xri -l. M t·,· · · } .. r r --+
iE jI E $r
i A IJ
· ·B 1·

A
r f- M« : AiO ... r f- M r, - I : A i (ri- I ) r f- N:
--+ j E $ r i
r r iE / ijBi

r f- L i , M« , . . . , M ri _ 1 'N : B,

where i is any element of I .

,B-la w s
let M be x . N
pm (i ,Afj) as {... , (i, xj ).Ni , ... }
a , Afj'A{ . . . , L i , xj .N i , . .. }
1]-laws
N [M / z ] pm M as {. . . , (i, xj) .1j(i , xj)/z]' ... }
M A{... , L i , xj .(Li , x j'M) , . .. }

Figure A.l . Syn t ax and Equations of Jumbo A-calculus

A.2 Languages and Translations


In t he res t of t his chapte r we will look in detail at various languages involving
effects , and t he t ranslatio ns between t he m, shown in Fig. A.2. Arrows of the form Y
indi cat e language extensions. For t he three lan gu ages marked with an asterisk, we
prov ide an equat ional t heory.
APPENDIX A: Technical Treatment of CBV and CBN 303

coarse-grain
lazy

/
CBV

fin~ifvain / B
N'
f ~BPV
fine-grain
CBV
+ complex
values"

CBPV
+ complex
values"

Figure A. 2. Effectful Lan gu ages

Becau se we are cons idering so m an y languages, we have m an y variants of t he


sa me result s. To reduce clutter , we omit many of t hese prop ositions, where t hey ar e
straight forward. Furthermore, when t reating CB V and CI3N, we omit proofs when
t hey are sim ilar t o the corresp onding proofs for CI3PV. We give a sum mary of t he
resul ts here.
Each language has t he following pr op er ti es:
• t he big-step semanti cs is total, because the only effect we ar e using in our lan-
guages is printing
• deno tational semantics com mutes with substitution and with weak ening
• denot ational sem antics agrees with op erational sem antics (soundness)
• denotational equalit y implies obse r vat ional equivalence.
Each equat ional t heo ry has t he following proper ti es:
• pr ovable equality commutes with substit ut ion and weak ening
• pr ovable equality implies denot ati on al equality
• pr ovable equality implies observational equivalence.
Each t ranslation has t he following pro perties:
• t he t rans lation preser ves de notational semant ics
• t he t rans lation commutes wit h su bstit ution and weakening up to pr ovabl e equality
304 CA LL-B Y-PUSH- VALUE

• t he t rans lation pr eserves provable equa lity (whe re t he source lan guage has an
equat ional t heory)
• the translation preserves and reflects ope rational semantics for gro und terms
• t he translation reflects observational equivalence.
We would like each trans lation to have t he following propert ies:
• t he translation com mutes exac t ly with subst it ution and weakening
• t he translation preserves and reflects ope rational semantics for all terms .
However , t hese pro pe rties usu ally fail, and t o achieve t hem we have t o extend t he
trans lation from a fun ct ion between terms t o a relati on between terms .
T he t wo t ranslations int o CBP yl have t he following pr op er ti es:
• every type in t he target lan gu age is isomorphic t o t he t ranslation of some ty pe in
t he source lan gu age
• every term in t he target langu age (of appropriate ty pe and context) is provably
equal t o t he tran slati on of some term in t he source langu age
• t he trans lation reflects provable equality
• t he trans lation preserves observationa l equivalence (full abst raction ).

A.3 Call-By-Value
A .3.1 Coarse-Grain Call-By-Value
For CG-CBY we evaluate t o t he following term in al closed te rms :

T ··= (t , To, ... , TT,- l ) I '\{... , L:i , x:!.Mi , . .. }


The relati on M JJ. T is given inductively by t he rules of Fig . A.3. We extend it to
print ing as in Sect . 2.4.1.

Proposition 132 Prop er ti es of big-st ep sem antics:


1 If T is terminal , then T JJ. T .
2 For every closed term M, M JJ. T for a unique T.

Deno t ational semantics for printing is given as in Sect . 1.6.2 . The ty pe constructors
are inter preted as follows.

• L, ixi /E$Ti A i j deno t es L,iE/([ A i O] x ... x [Ai (T i-1) ])'

• I1 :~E$ri Aij E i denot es I1 iE/ ([A i O] -7 . .. -7 [A i( Ti- i)] -7 (A · x [E;]) ).

1 We ha ve no t investigate d these properties for t he ot her t ra nsl at ions.


A PP ENDIX A: Technical Treatment of CB V and CBN 305

M JJ-T N[ T / x ] JJ- T '

let M be x . N JJ- T'


M o JJ- To . . . M r; -I JJ- T r;-I

(i, M o , . .. , M r, - I) JJ- (i , To, .. . , T r;- I)

M JJ- (i,~)
pm M a s {. . . , (i , ij ).N i , . . .} JJ- T

A{ . . . , L i , ij.Mi,.. .} JJ- A{ .. . , L i , ij.Mi,.. .}

M o JJ- To . . . M r; -I JJ- T r;- I N JJ- A{ ... , Li, ij .Ni , ... }

L i ,Mo, .. . , M r, - I' N JJ- T

Figure A .3. Big-Step Sem an tics for CG -C BV -No Effects

A.3.2 Fine-Grain Call-By-Value


The Language
T he coarse- gr ain CBV lang uage t hat we h ave see n suffers from two pro blem s.
1 We h ad to m ak e an arbitrary cho ice as t o the orde r of evaluati on of t u ples and
applicat ions .
2 A value V h as t wo denotation s : [V]"al, it s d en ot at ion as a valu e, an d [Vr" t, it s
den ot at ion as a returner .
Ho w ca n we refin e t he langu age to avo id t hese prob lem s , whi le leaving unch ang ed t he
typ es an d t he ir den ot ati on s?
In or der to h ave a sing le den ot at ion fu nction [-] , we make a sy ntactic distinction
b etween val ues and returner s, so t hat eve ry term is eit he r a value or a returner but
not b ot h . T hus we have two j udgem en t s

r f-v V : A

wh ich resp ect ively say t hat V is a va lue of type A and t hat M is a returner of typ e
A (i.e, M ret urns a value of t yp e A ).
The calculus t hat t his lea ds t o is called fin e-grain en V. The terms an d big- st ep se-
m antics are given in F ig. A .4. We do not evaluate values , so t he op er ati on al semantics
is defin ed only on returner s.
It is conve n ient in FG -CBV to write TA as sy ntact ic sug ar for I1 E{*}A. Thus in
t he print ing sem antics T A denot es A * x [A ], an d in t he Scott semantics T A den ot es
[A ]l- . We write thunk M for A *.M an d force V for *'V . Because of t he im p ort ance
of T A , we present ru les and equat ions for it exp licit ly, even t ho ug h t hey are j ust
sp ecia l cases of t he rules a nd equ ations for funct ion ty pes.
Note t hat in FG-CBV let is used only for binding ide ntifiers. The sequencing of
returner s, wh ich was wr itten in CG -CBV as let M be x . N is in FG-CBV wri t t en
306 CALL-BY-PUSH- VAL UE

r f-v V : A r ,x : A f-P M : B

r ,x : A , r' f-v x : A r f-v let V be x. M : B

r f-v V : A r f-P M : A r ,x : A f-P N : B

r f-P return V : A r f-P M to x. N : B

r L V
r
('Z, =7)
Vj
" , X j E $r iA
: LJ i E I ij

-------,----t
r f-v V . " , X j E $ r i A ·· ... r , Xj : A i j f-P M i : B ... i EI
. LJ i E I 'J

r f-P pm V as { . .. (i , ? ).Mi , ... } : B


-------,----t
r ,Xj : A i j f-P M, : B , .. . iEI

r LV
r
'{
A
r:
••• , L ~, Xj .
:::-+ M i , · · ·
} :
n --+ j E $ r i
i EI
A ij B i

r LV
r \Ij :
A i j) r LV
r W :n --+j E $ r .
i EI '
A i j Bi

r f-P Lt, ~ 'W : e,


r f-P M : A r f-v V : TA

r f-v thunk M : T A r f-P force V : A

M[V/x].J,J. W
let V be x. M .J,J. W

M .J,J. V N [V/ x] .J,J. W


return V .J,J. V M to x . N .J,J. W

pm (i , ~) as { ... , (i, xi ).Mi , ... } .J,J. W


---+
Mi [Vf / Xj].J,J. W
Lt, ~ 'A{ . . . , a , xi. M i , . . .} .J,J. W
M .J,J.W
force thunk M .J,J. W

Figure A.4- Terms and Big-St ep Sem an t ics for FG -CBV


APPENDIX A : Technical Treatment of CBV and CBN 307

more sugge stively as M to x. N . Furthermore this is the only const ruct in FG -


CBV t hat seq uen ces returners , so bo th op erational and den ot ational sem antics for
other terms (such as application) is mu ch simpler than before. In part icular , the
arbit rar iness present in CG-CBV (evaluation order for application and for t upling) is
no longer pr esent in F G-C BV.
FG-CBV is based on Moggi's "monadic metalanguage" [Moggi, 1991]. Bu t unlike
Moggi's calculus, FG- CBV distinguishes b etween a returner M of ty pe A and its
t hunk, a value of typ e T A.
To add our example effect to the language, we add t he rul e

r f-P print c. M : A

and adapt and t hen exte nd t he big-step sem ant ics exact ly as in Sect . 2.4.1. We t he n
ob t ain :

Proposition 133 For every closed returner M , t here is a un iqu e m , V such t hat
M .u.m,v. 0

Observational Equivalence
Definition A.2 Given two returners I' f-P M , M ' : B , we say that
1 M ~ground M ' wh en for all ground returner conte xts C[·], C[M] .u. m , i iff C[M'] .u.
m ,i
2 M ~anytype M' when for all returner conte xts C[·] of any type, C[M] .u. m , T for
som e T iff C[M'].u. m , T for some T
Similarly for valu es. o

Proposition 134 The two rela tions ~ground and ~anytype ar e the same . o

Denotational Semantics for Printing


The sem ant ics of ty pes is t he same as CG-CBV.
If r f-V V : A then V denotes a fun ction from [r] t o [A] , whereas if r f-P M : A
t hen M deno te s a fun ction from [r] to A * x [A]. We omit t he semantics of t erms.

Complex Values and Equational Theory


For all purposes excep t operational sem antics, we exte nd the FG-CBV calculus
with the following rules for com plex values :

r f-v V : A r ,x : A f-v W : A

r f-v let V be x . W : A

I' L V V . " , X j E $ ri A · . . .. I' , Xj : A i; f-v W i : B . .. i E I


,- . LJ i E I 'J

I' f-v pm V as { . . . , (i , xJ) .Wi , ... } : B


We t he n form the equational t heory shown in Fig. A.5. M ,N and P ran ge over
ret urners , whil e V and W rang e over values.
308 CALL-BY-PUSH- VALUE

.a- la w s
l e t V be x . M M[V/xJ
l e t V be x. W W[V/xJ
(r e t ur n V) t o x. M M[V/xl
pm (i, ~) as { , (i, X"j ).Mi , } M;(Vj/x{ J
pm (i, ~) as { ,(i, X"j) .Wi, } W;[Vj/X{J
Li, ~ 'A{ . . . , a , X"j .Mi, .. .} M;(Vj/x jJ
for ce thunk M M

1)- la ws
M M to x . return x
M[V/ z] pm V as { , (i, X"j) .M[(i, X"j) / z]' }
W[V / zJ pm V as { , (i, X"j ).WJ (i, X"j )/ zJ, }
V A{. . . ,Li, X"j .(Li, x/ V), .. .}
V thunk force V

seq uen ci n g laws


(M to x. N) to y. P M to x . (N to y. P)

print law s
(print c. M) to x . N pri nt c. (M to x . N )

Figure A .5. CBV equations , using conv entions of Sect . 1.4.2

The equat ion for print is of course spec ific t o our exa m ple effect, bu t there ar e di-
rectly analogous eq uations for man y other effects. For example, if we wer e considering
div ergence, we would have an equation

d i verge to x . M = diverge
We call this theory (without the print equation) the CBV equational theory.

Proposi tio n 135 1 T here is an effect ive procedure that given a ret urn er I' f-P M :
A, possibly containing complex values , returns a returner I' f-P 1\1 : A without
complex values , such that M = 1\1 is provable.
2 There is an effective procedure that , given a closed value f-v V : A, possibly
cont aining complex values, returns a closed value f-v V : A witho ut complex
valu es, such that V = V is provable.
o

This is proved like Prop. 25.

A.3.3 From CG-CBV To FG-CBV


The translation from CG-C BV to FG-CBV is given in Fig . A.5. It is in t wo parts:
- cg is defined on returners and - cgval on value s. The trans lation - cg reflects our cho ice
of evaluation order for CG-C BV.
APPENDIX A : Technical Treatme nt of CB V and CBN 309

r f-M :A r f-P Mcg : A


x return x
let M be x. N Mc g to x. Nc g
(i , M o , . . . , Mri-J) M~g to XO. . . . M~~_ l to Xri -l. return (i ,xi)
pm Mas {. . . , (i , xi) .Ni , . . .} Mcg to z. pm z as j ...,
(i , xi). N iCg , . . .}
A{. .. , L i , xi. M i , . . .} return A{ , L i , Xj . M~g, ... }
L i , Mo, .. . , M ri - 1 ' N M~g to XO M~~_ l to Xri- l . N cg to f. Li, xi' f
print c. M print c. Mc g ,

r i-v .» r f-v Vcgv•1 : A


x x
(i , Vo, . . . , Vri -J) (i , vocgv•l, . .. , Vrc.g~·i)
A{... , L i , xi .Mi , ... } A{. . . , L i , xi .M }g, . . .}

Figure A .6. Tr anslation from CG-CB V to FG -CBV

We now address the tec hnical pr op erti es of t he t rans lation. It neither commutes
with substitution nor preserves op erational sem an t ics.
substitution It is not t he case t hat (M[V/x])'g and M cg[vcgv.l/x] are the same term
(although t hey will are provably equa l in the CBV equational theory of Fig. A.5).
To see t his, let M be x and V b e (0, (0)) , where 0 is a tag. Then
g
(M[V/x])C return (0) to x. return (0 , x)
M cg[V cgv.1 / x] return (0 , (0))

operational semantics It is not t he case t hat M -lJ. m, V implies Mcg -lJ. m , V cgv.' .
For examp le, let M b e let (0 , (0)) be x. A * .x.
T he issu e is t hat CG-C BV cannot rec ognize t hat what is substit ute d is not a cer tai n
kind of returner (t o be t rivially reevalu at ed when required) bu t somet hing genuinely
different - a value .
To salvage wha t we can, we pro ceed as follows. First , we writ e t he two t rans lations
as relations I-t cg and I-t cgv•1 from CG-C BV t o FG -CBV te rms . We can pr esent F ig. A.6
by rules suc h as t hese :

M I-t cg M' N I-t cg N'


cg
let M be x. N I-t M ' to x. N'
. . . Pi I-t cg P: .. . iEl

A{. . . , a . xi .pi , . .. } I-t • A{... , a , xi .p: , ... }


cgv 1
To t hese rul es we add t he followin g
cg
M I-t return Vo to xo. . . . return Vri- l to Xri-l . return (i, xi)
cg
M I-t return (i,~)
(Strictl y, we shou ld write weakenings t o indicate that Xj is not in t he context of Vj ,.)
We have t hus defined non-functi on al relations I-t cg and I-t cgv•l, and we will show that
t hey com mute with su bstitution and preserve and reflect ope rat iona l semant ics.
310 CA L L -B Y-PUSH - VAL UE

Proposition 136 For any returner M , we have M H cg Mcg , and if M H cg N t hen


N = Mcg is provab le in t he CBV equational t heo ry of Fi g. A.5 ; similar ly for values.
o

Proposition 137 1 If V Hcgval V' t hen V H cg return V' .


cg cg
2 If M H M ' and V Hcgval V' t he n M [V/ x] H M '[V' Ix ].
var cg
3 If W H cg W' and V H cg V' t hen W [V/ x] H W '[V' I x].
o
cg
Proposition 138 1 If M .ij. V and M H M' , t he n , for some V ' , M' .ij. V' and
V H cgval V ' .

2 If M H cg M' and M' .ij. V ' , t hen, for som e V , M .ij. V and V H cgval V'.
o

To prove t his, we introduce t he following.

D efinition A.3 1 In CG-C BV, t he following return ers ar e sa f e :

S x I let S be x . S I (t, B;)


I pm Sas { . . . , (i, xj ).Si, . . .} I A{.. . , L i, xj .M i, ... }

2 In FG- CB V the following returners ar e saf e :

S return V I l e t V be x . S IS to x . S
I pm V as { . . . , (i , xj ).Si, . .. }

In summ ary, a return er is sa fe iff, inside it , every application occ urs in t he scope of a
A.

cg
Lemma 139 Su ppo se A o , .. . , A n - 1 f- M H M ' : B . Then
1 M is safe iff M' is safe.
2 Suppose M is safe and Uo H cgval U~ , ... , Un-l H cgval o:. , i U, and U; may not
be safe).

-----t ~]'
• If M [Ui/X;] .ij. V , t he n , for some V , , M , [Ud Xi .ij. V a nd V H
c al
gv V,.

• If M'[U; /x : ].ij. V ' , t hen, for some V , M [U;j x:].ij. V and V Hcgval V' .

We prove t his by induction on M H cg M ' . F inally we prove Prop . 138 by ind uction
on M.ij. V (for (1)) and on M ' .ij. Vi (for (2)) .
APPENDIX A : Technical Treatment of CBV and CBN 311

N [M / x] .l).T
let M be x. N .l). T

M .l). (i, N;)

pmM as { oo . ,(i,xj).Pi , . . .}.l).T

A{. .. , L.i , xj.Mi, . . .} .l). A{... , Z i, xj .Mi, ... }


----t
N .l). A{. 00' L.i, xj .Ni , oo .} N;[M j/xj].l). T

L.i,M~i'N .l).T

Figure A. 7. Big-St ep Sem antics for CBN-No Effects

A.4 Call-By-Name
For CBN we evaluate t o t he following terminal closed terms:

T "= (i, Mj) I I A{oo . , a, xj .Mi , oo .}


The relation M .l). T is defined in Fig. A.7.

Proposition 140 For each closed te r m M , we have M .l). T for a unique term ina l
te r m T . 0

To add our exam ple effect , we adapt and extend F ig. A.7 exactly as in Sect . 2.4.1.
We then have

Proposition 141 For every closed t erm M , t here is a unique m , T such t hat M .l).
m ,T . 0

The printing sem an ti cs follows Sect . 1.7.4. T he in terpret ation of ty pe constructors


is given by
• If [Ai j] = (Xi j , *), then n= :~IE $ri A i j] is t he free A- set on L: iEI(Xi O x ... x
X i (Ti- 1 »)'
• If [A i j] = (Xi j , *) and [Ed = (Yi, *) t he n [IT~~E $ri A ij Ed is t he A set ITiE1(X i 0 -+
.. . -+ Xi(Ti -1) -+ (Yi, *))
We define an equational t heory for CB N , whose axioms are t he equations in
Fi g. A.8 .
T he equations for print are of course spe cific t o our example effect, bu t t here
would be d irectly analogous equations for man y other effect s. For example, if we
were cons idering diverg en ce, we would have equations :

diverge pm diverge ~s J .:, (i , xj) .Ni , . . .}


diverge A{. . . , L.~, Xj .d f ve r ge , .. .}
We call t his t he ory (withou t t he print equations ) the a BN equatio nal theory.
312 CALL-BY-PUSH- VALUE

(3- la w s
let M be x . N
pm (i, Mj ) a s {. . . , (i , x)) .Ni , . . .}
Lt, Mj'A{ ... , a , x) .N i , .. .}

7]-l a ws
M A{. . . , Li, x) .(L i , x)'M ), .. .}
p a t t ern-ma t ching la w s
M pm M a s { , (i, x) ).(i, x) ), }
pm M as {.. . , (i , x} ) .(pm N; as { , (k , yt .Pk, . . .}), }
pm (pm M as {. . . , (i , x}) .Ni , }) as { , (k , yt) .Pk , ... }
pm M as { . . . , (i, x} ).A{ . . . , L k, yt .Nik, } , ... }
= A{. .. ,Lk,yt.(pmM as { , (i, x} ).N i k, . . .}) , . . .}
print laws
print c: (pm M as { . . :,~ ,x}).Ni ' .. .}) pm (pr i nt c.. !1!1
as ~ . .. , (i , x} ).Ni ' . . .}
pnnt c. A{ ... , L z, xj .Mi, . .. } A{. . . , L z, xj .(pn nt c. Mi) , ... }

Figure A .B. CBN equations , using conventions of Sect . 1.4.2

A.5 The Lazy Paradigm


Recall from Sect . 1.7.3 t hat t he lazy paradigm is defined to have t he same op era-
t ional semantics as CBN , bu t to use ~anytype rather t ha n ~grou nd as its observational
equivalence . Thus it s models mu st not satisfy, for exam ple, t he 7]-law for fun ction
ty pes.
We shall say lit t le ab out t he lazy paradigm , b ecau se it is su bsume d within FG-
C BV. First , as in CG-CBV , we introduce a valu e/returner t er m ino logy.

D efinit io n A.4
A value is a lazy term wh ose su bst it ution instances ar e all terminal. Unlike in CBV
an identifier is not a valu e becau se an y term can be substituted for it , so value s are
just the following:

V ··= (i,Mj) I I A{ . . . ,Li,x} .Mi , . .. }

A returner is a lazy term (so-called beca use a closed returner returns a closed value) .
o
We translate t he lazy language into FG-CBV in Fig. A.9. The t ranslation is
essent ially that given in [R atcliff and Danvy, 1997]. Like t he trans lation from CG -
CBV to FG -CBV, t he translation on terms is defined in two parts: _ lazy is defined on
returners , and _ lazyvaJ is defined on valu es.
The t rans lat ion is motivated as follows.
• Id en tifiers in the lazy lan guage ar e bound to unevalu at ed te r ms , so we regar d
t hem (from a CBV persp ective) as b ound to t hunks.
• Similarly, t u ple-com ponents and ope rands in t he lazy language ar e un evaluated
te rms , so we regard t hem as t hunks.
APPENDIX A : Technical Treatment of CBV and CBN 313
• Consequently, identifiers, t uple-comp onents and op erands all have ty pe of t he
form T A- a thunk type .
T he t ranslation from lazy to FG-CBV is very similar to t he t ranslation from CB N to
CBPV.

", XjE$ri A . . ", XjE$ri TAlazy


L..J~I 'J L..J~ I ij
IT . jE$riA · ·B·
~EI ZJ t
IT.t EljE$ri T A lazYB
vs
lazy
t

Ao , . . . , A n-I f- M : B T A ~ZY, ... , T A~zy I f-P M1azy : B1azy


x force x
let M be x. N let thunk M1azy be x. N1azy
(i , M« , . .. , Mr,_I) return U, thunk M~azy , . . . , thunk M~~"!...I)
pm Mas {oo . , (i , xj). N j , oo. } M 1azy to z. pm z as { , t' , =+)
.. .( xJ . N i1azy, '. . . }
A{. . . , Z i, xj .Mi , . . .} return A{.. . , L.i , xj .M~azy , }
L.i , M o, ... , Mr, - I'N N 1azy to f . L.i , (t h unk M o) , , (thunk M r,-I)'!
print c. M print c. M1az y

Ao , . . . , A n- 1 f- V : B T A~ZY , . . . , T A~zy I f-v v 1azyval : B1azy


(i , M« , . .. , M r, -I) (i , thunk Moazy , . . . , t hunk Mr:z~ l)
A{. . . , Z i , xj .Mi , . . .} A{. .. , Z i , xj .M~azy , . .. }

Figure A .9. Translat ion from lazy to FG-CBV: t yp es, returners, valu es

T his t ranslation does not commute with substi tution or pr eserv e op erational se-
man ti cs precisely- onl y up t o the pr efix force thunk. (Recall that force thunk M =
M is provabl e in t he CBV equational t heory. )
substitution It is not the case t hat (M[Nlx])'az y and M1azY[thunk N 1azyIx] are the
sa me t erm (although t hey will be pr ovably equal in the CBV equational t heory )..
To see this, let M be x. Then (M[Nlx])'az y = N1azy but M1azY[thunk N 1azy Ix] =
force thunk N 1azy.
operational s emantics It is not the case t hat M .lJ. Tn, V implies M1azy .lJ. rn , v1azyval .
For example, let M be let (0) be x. (0, x) .
To make t he rel ationship pr ecise, we proceed as follows. First, we wri t e the two
t ranslat ions as relations H 1azy and Hlazyval from lazy t o FG-CBV te r ms. We ca n
present Fi g. A .9 by rules such as t hese :

1azy
let M be x. N H let (thunk M ' ) be x . N '

. . . Pi H 1azy P; ... iEI

A{... , Z i, xj .Pi , . . .} Hlaz yval A{ . .. , Z i , xj .P; , . .. }


To these r ules we add the following:

M H 1azy force thunk M'


314 CA LL-B Y-PUSH- VALUE

Proposi tion 142 For any returner M , we have M >--+ Iazy M lazy, and if M >--+Iazy M '
t he n M ' = M1azy is provable in t he CBV equational t heory; sim ilar ly for values . 0

Proposi tion 143 I If V >--+Iazyval V' t he n V >--+Iazy return V' .


2 If M >--+Iazy M ' and N >--+ Iazyval N' t hen M[N/ x] >--+Iazy M ' [t hunk N' / x].
3 If W >--+Iazyval Wi and N >--+ Iazyval N ' t hen W[N/ x] >--+ Iazyval W'[t hunk N' /x].
o
Proposition 144 I If M .ij. V and M >--+Iazy M ' , t he n , for some V I, M ' .ij. V i and
V >--+ lazyval V I.

2 If M >--+Iazy M ' and M ' .ij. V ', t he n, for some V , M .ij. V and V >--+ Iazyval VI .
o
We prove t hese by induction primarily on .ij. and secondarily on >--+Iazy .

A.6 Subsuming FG-CBV and CBN


The t rans lat ions into CB PV are eas ily ob tained by cons idering deno t ational se-
m antics.

A.6.1 From FG-CBV to CBPV


T he t ranslation from FG-CB V is given in Fig. A. I O.

Propo si tion 145 For a returner M , (M[V/ xJr and M V[Vv /x] are t he same te rm;
and similarly for values. 0

Proposi tion 146 For returners r I-P M , N : A , if M = N is provabl e in t he CBV


t heo ry t he n M V = N V is provable in the C BPV t heo ry ; and similarly for values. 0

Proposition 147 T he t rans lation .:» pr eserv es and reflects operational sem ant ics:
I if M .ij. V t he n M V .ij. return V V
2 if M V .ij. return V ' t he n M .ij. V for some V such t hat VV = V'.
o

A.6.2 From CBPV Back To FG-CBV


Our a im is t o prov e t he following.

Prop o si tion 148 I An y CBPV value ty pe A is isomo r phic to B V for some C BV


ty pe B.
2 For any CBP V returner A ov , • . . , A n - 1v I-c N : F B V t here is a n FG -C BV returner
A o , .. . , A n - 1 I-P M : B such t hat M V =N is provabl e in CBPV; and sim ilar ly for
values.
3 For any FG-CB V returners r I-P M , NI ' : B , if M V = M ' V is provable in C BPV
t hen M = M ' is prova ble in FG-C BV ; and similarly for values.
(2)-(3) ca n be extended to terms with holes i.e. contexts. 0
APPENDIX A : Technical Treatment of CBV and CBN 315

C C V (a value type)
A..
)"'X j E $ ri
L: iE/(Ai OV x · · · x A i (r i _ 1 )V)
~i E/ 'J
ses-, A B
IT iE I ij i UIT iE/(A i OV -+ .. . -+ A i (r i _ 1 )v -+ FB;')
TA UFN
A o, . . . , A n - 1 f-v V : B
x x
(i, Vo, , Vri-I) Ct, (VoV, , Vr i - 1 V))
A{.. . , Li , xn, ,X r i - 1.M i , . . . } thunk A{. . . , i.AXO AXr i -1.Mi " ; .. . }
thunk M thunk M V
A o, .. . , A n - 1 f-P M : C AoV, . . . , A n - 1 v f-c M V : FC v
let V be x. M let VV be x. M V
return V return VV
M to x. N M Vto x. N V
pm Vas { , (i , X;) .Mi , ...} pm VV as {. . . , (i, (X;)) .MiV, . ..}
Li, Vo, , Vr i - 1 'W Vr i - 1 " •• • ' Vo" i'f or ce W V
force V force VV
print c. M print c. M V
When we add complex values to the sour ce language FG-CBV, we must add them
also to the target language CBPV, and we then extend the t ranslat ion as follows:

A o , .. . , A n - 1 f-v V :B
let V be x. W let VV be x. W V
pm Vas { . .. , (i , X; ).W i , .. .} pm VV as { ... ,(i,(X;)) .WiV, . . .}

Figure A.1 O. Translation of FG-CBV types, values and returners

Corollary 149 (Full Abstraction) For any FG-CBV returners Ao, ... , A n - 1 f-P
M , M' : B , if M ~ M' t hen M V ~ M" ; and sim ilar ly for valu es. (The converse is
trivial.) 0

Proof Suppose C[M V] -lJ. rn , return i , for some CBPV ground context C of type
FL:iE/l. Construct a FG-CBV context C' su ch that C" = C is provable in CBPV.
Then we reason as follows.
1 Since in CBPV provable equality implies obs ervational equivalence, (C'[M])' -lJ.
rn , return i using the fact that (C'[M])' is precisely C"[M V] .
2 By Prop. 147(2) , C'[M] -lJ. m, i .
3 Since M ~ M' , we have C'[M'l-lJ. Tn,i.
4 By Prop. 147(1) , (C'[M'Jr -lJ. rn , i .
5 Since in CBPV provable equality implies observational equivalence, C[M 'V] -lJ.
rn , return i.
The proof for valu es is similar. 0
- 1
To prove Prop. 148, we give a translation .:» from CBPV to FG-CBV. (We shall
see that , up to isomorphism, it is inverse to _v .) At first glan ce, it is not apparent
how to make such a translation. For while it will translate a valu e ty pe into a CBV
316 CALL-BY-PUSH- VAL UE

ty pe, wh at will it t ranslate a com put at ion type into? T he answer is: a family of pairs
of CBV ty pes {(Bi , C i )}i EI. To see t he principl e of t he t rans lation , we not ice t hat in
CBPV (following Prop. 27) any computation type mu st be isomorp hic to a ty pe of
t he form Il iEI (Bi -+ F C i ). This motivates t he followin g.

D efinition A. 5 • A CBV pseud o-computatio n-type is a family { (Bi , C i )} i El of


pairs of CBV ty pes .
• Let A o, ... " A n - I b e a seque nce of CBV types and let { (B i , C i)}; El b e a CBV
pseudo-computation-type. We write

Ao, . . . , An - I I-CBV { M i}; EI : {(Bi , C ;) };EI

t o mean t hat , for eac h i E I , M, is an FG -CBV returner A o , ... , A n- I , n :


B, I- M, : C«. We say t hat {M;} iEI is an FG- CBV ps eudo- computation of typ e
{(Bi , C i)}; EI on the context A o, .. . " A n- I. Giv en two such pseudo-computations
{Mi}; EI and {N;} iEI , we say t hat they are pro vably equal in CB V wh en for each
i E I the equat ion M, = N, is provable in C BV .
o
Before pr esenting t he reverse t ranslat ion , we exte nd t he forward t rans lation as
follows:
• Given a C BV pseudo-comput ati on-typ e { (A i , B i ) };EI , we wr it e { (A i , B i ) };EI V for
V V
Il iEI (A i -+ FBi ) .
• Given an FG-CB V pseudo-comput ati on

Ao, . .. , An-l l-es v { M i };Ef : {(Bi , C i)} iEI

we wri te { M i };EI V for

A o", . . . , A n_ I 1-< >.{.. . , i .>.n M i", ... } : { (A i , B i ) };E/


V

It is clear t hat the exte nde d t ranslation pr eserv es provabl e equa lity.
The reverse t rans lation , pr esen ted in Fig. A.ll is organi zed as follows:
- I
• a valu e ty pe A is t rans lated into a CBV ty pe A V
- I
• a computat ion typ e ll. is translated int o a CBV pseudo-computation-type ll.v
• a CBP V value A o, . . . , A n - I I- v V : B is translat ed into a CBV value
v- I v- I v v- I v- I
A o , . . . , A n - I I- V :B
• a computat ion A o , . . . , A n - I 1-< M : ll. is tran slated into an FG -CBV pseudo-
A v- I c
.
co m p uta t io n ° ,...,
Av-I
n- I I- CBv M
v- I
: ll.
v- I
.
It is easy to show t hat t he reverse t rans lation com mutes with substit ution (of
valu es), and t hence t hat it pr eser ves pr ovable equality.
Using t his t rans lation (and a resul t t hat it ag rees with ope rational sem ant ics in a
certain sense) we ca n obtain from t he printing den ot ati on al semant ics for FG-CB V an
alte rnative semantics for C BPV . Thus a computation ty pe will denote a family of pair s
of sets and a com putation will denot e a family of fun cti on s. More generally we ca n
obtain a C BP V semantics from any FG-CB V semantics. However , t he construction
is artificial and we ar e not aware of any natural mod el for C BPV t hat ari ses in t his
way.
A PPENDIX A : Technical Treatment of CBV and CBN 317

A where

B wh ere
{(I , A' )) i E { *}

{(A kl ' B kl)} kEK,IEL k


- I
{(A' X A i , B i ) }; EI

v V·- 1
x X
- I - I
let V be x. W let V ' be x. W '
(h, V ) (h, V· - I
)
- 1 - 1
pm Vas { ... , (k, X),W k" " } pmV' as{ . .. , (k, x) .Wk' , . . .}
(V, V ') (V ·- I , V ,· - I)
- I -I
pm V as (x , y ).W pm V ' as (x, y) .W'
- I
thunk M A{ . . . , L i, n.M i , ... }
M where
let V be x. M let V' be x. M'[
- I
return V ret ur n V '
- 1 - 1
M to x . N M: [O / n] to x. Ni
f or c e V a ,n 'force V ' -I

- I -I
pm V as {... , (k , x ).Mk , ... } pm V ' as {. . . , (k , X).(M k )i , . . .}
- I - I
pm V as (x, y ).M pm V ' as (x, y).M i
= (h,i)
-I
A{. . . , k .M k , .. . } (MiJi l
- I
h'M Mk~ '
1 - I
Ax.M pm n as (x, n). M i
- 1 - 1
V 'M Mi [(V' , n) / n]
- I
print c. M print c. M]

- I
Fiqu re A.ll . T he Re verse Translation .:»

To show that t he two t rans lations are inv ers e u p to isomorphism , we first const r uct
t he isomorphisms.
I For each CBV ty pe A we define a fun ctio n QA from CBV values I' l-" V : A to
I
CBV values I' f-' W : A··- , and a fun ction QA 1 in t he opp osite direct ion .
2 For each CBP V value ty pe A we define a fun ction (3A from CBP V values I' f-' V :
A to values I' f-' W : A · - I. , and a fun ction (3A 1 in t he op posite direction.
3 For each CBP V com putation ty p e !l we define a fun cti on (3l! from CBPV com-
pu t at ions r f-c M : !1 to CBP V com putations r f-c N : !l.- I. and a fun ction (3/"/
in t he opposit e direct ion . -
318 CALL-BY-PUSH- VALUE

(1) is defined by induction on A. (2) and (3) are defined by mutual induction on A
and 11- We omit the definitions, which are straightforward.

Lemma 150 (properties of Q and (3)


The following equations ar e provable in t he CBV equat ional theory.

QA(W [V/X]) (QAW)[V/X ]


QAQA: 1V V
QA: 1QAV V

The following equ ations are provable in the CBPV equational theory.

(3A(W [V/ X]) ((3A W) [V/x ]


(311(M[VI x]) ((311M)[W / x]
(3A(3.:\ l V V
(3.:\ 1(3AV V
1
(3!l(3i M M
1
(3i (311M M
(3ll(M t o x. N) M to x. (3!l N
(3ll(pr i nt c. N) print c. (3!l N
(QAVr (3A' (VV)

These are each proved by ind uct ion over types. Using (3A, we have now proved
Prop. 148(1).
The tran slations are inv erse up to these isomorphisms, in the following sense:

Le mma 151 For an FG-CBV value A o, . . . ,A n - 1 f-v V: B , we can prove in CBV

For an FG-CBV returner A o , . . . , A n - 1 f-P M : B , we can prove in CBV


vv - 1 )
M. [QAix ;jxi , O/ n] =M to x. return QBX

For a CBPV value A o , . . . , A n - 1 f-v V : B , we can prove in CBPV

For a CBPV computation A o , ... , A n - 1 f-c M : 11, we can prove in CBPV

These resu lts can be extended to terms with holes i.e, contexts. D

T his is proved by induction over terms using Lemma 150.


We ar e now in a position to prove Prop. 148(2)-(3) . Fix a CBV context A o, . . . , A n - 1
and CBV type B .
A PPENDIX A: Technical Treatment of CBV and CBN 319

D efinition A.6 1 For any CBPV value A o" ... , A n - I v I-v W: B V define t he FG -
CBV value OW to be
v - I v- I [ )]
A o, ... , A n - I I- aB W aAix;j xi : B

2 For any C BP V returner A ov, .. . , A n - I v I-c N : F B V define t he FG -C BV returner


ON to be

A o, .. . , A n - I I-P N .v-I [ aAixi / xi) ]


, O/n to y. return a - I
B Y: B

o
Lemma 152 1 For any CBPV ret urner Ao", . . . , A n - Iv I-c N : F B V , t he equation
(ON)" = N is prova ble in C BPV.
2 For any FG-CBV returner A o, . . . , A n - I I-P M : B , t he equation O(M V) = M is
provabl e in CBV.
Sim ilar ly for values . This can all be extended to t erms with holes i.e, contexts. 0

P roof

(1) By Lem ma 151 , N = 1 -1 )


f3 F B v N v V[f3 AiXi/X;] is provable, and we ca n see that
1 v -1 )
f3 F B v N V[f3 AiX;jX ;] = (ON)" by ex panding both sides and us ing Lemma 150.
(2) This follows direct ly from Lem ma 151.
T he proof for values is sim ilar . o
Prop . 148(2)- (3) follows im me diately from Lem m a 152.

A.6.3 From CBN to CBPV


e en (a com putation ty pe)
", Xi E$r' A '·J·
L..Ji E /
F '" (An An )
L..Ji E / U iO x· · · X U i( r, - I)
D :~E $ri A ij B i D iE/ (UAi'O-t . .. -t UAi (r, _I ) -t Ei)
A o, .. . , A n - I I- M : e U AD ," . , U A~_I I-C M" : en
x force x
let M be x. N let thunk M" be x . N"
(t, M« , . . . , Mr;-l ) return (t, (t hunk M& , .. . , thunk M;. -l ))
-t . ~ •
pm M a s { ,(i, xj) .Ni, } M to z . pmz as { , (z, (Xj )) .Mi , . . .}
>.. {. .. , Li, xo, , Xri - l .Mi , } >..{ .. . , i .>"xo >"Xri - I. M ;", . .. }
a , M«, , Mr,-l'N (t hunk M;, -d ' · · · (thunk M&)'z'N

Figure A .12. Tr ansla tion of CBN ty pes and te rms

Lemma 153 Given CBN te rms I' I- N : A an d I' , x A I- M B , the eq uation


M [N/ x]n = M n[t hunk N n/ x] is prova ble in CBPV. o
Proposition 154 If M = N is provable in t he C BN eq uational t heo ry t he n M" = N"
is provabl e in t he C BPV equational t heory. 0
320 CALL-BY-PUSH- VALUE

The te chnical treatmen t of this t ran slation is also very sim ilar to t he trea tment of
t he t ranslation in Sect . A.5.
T his translation does not com mut e with substit ut ion or preserve op erational se-
man t ics pr ecisely-only up t o t he pr efix force thunk. (R ecall t hat in t he CBV equa-
tional theor y, we have
force thunk M = M .)
substitution It is not the case t hat (M[N/x])" and M "[thunk N" /x] are t he same
term (although t hey will be provabl y equal in the CBPV equational theor y) . To
see this, let M b e x. T hen (M[N/x])" = N " but M"[thunk N" /x] = force thunk N ".
operational semantics It is not the case t hat M .ij. m, T implies M" .ij. m , T" . For
example, let M be let (0) be x. (0, x) .
To m ake the relat ionsh ip pr ecise , we proceed as follows. First , we wri t e t he t rans-
lation as a relation >--t" from CBN t er ms to CB PV computat ions. We can present
Fig. A.12 by rules such as t hese :

M >--t" M' N >--t" N'

let M be x. N >--t" let thunk M' be x. N '


To these rules we add the following:

M >--t" force thunk M '

Lemma 155 For an y term M , we have M >--t" M" , and if M!-t" M ' t he n M ' = M"
is provabl e in t he CB PV equat ional theory. D

Lemma 156 If M >--t" M ' and N >--t" N' t hen M[ N/x] >--t" M'[thunk N' /x]' and
similarly for multiple su bs tit ut ion. D

Proposition 157 1 If M .ij. N and M >--t" M' , t hen, for some N ' , M' .ij. N ' and
N >--t" N ' .
2 If M!-t" M ' and M ' .ij. N', t he n , for some N , M.ij. Nand N!-t" N ' .
D

We prov e t hese by indu ction primarily on .ij. a nd secondar ily on !-t".

A.6.4 From CBPV Back To CBN


Our aim is t o prove t he following.

Proposition 158 1 Every CBPV com putat ion type !1 is isomorphic to B" for
some CBN type B.
2 For any CBPV com put at ion U A 3, . . . , U A~ _l I-- c N : B" t here is a CBN te r m
A o, . . . , A n - 1 I-- M : B su ch t hat M" = N is provabl e in CB PV .
3 For any CBN terms I' I-- M , M' : B , if M" = M '" is provabl e in CBPV then
M = M ' is provable in CB N .
(2)-(3) can be extende d t o te rms with hol es i.e. conte xts. D
APPENDIX A: Technical Treatment of CEV and CEN 321

Corollary 159 (Full A bstraction) For an y CBN t erms A o, . . . , A n - I I- M , M' :


B , if M ~ M ' t hen M " ~ u" , (T he converse is t rivial.) 0

T he proof is sim ilar to t hat of Cor . 149.


- 1
To pr ove Prop. 158, we first give a t rans lation _ n from CBP V to CBN. (We
shall see t h at, up to isomorphism, it is in verse t o _n.)
At first glan ce, it is no t appar ent how to m ake such a trans lation . For wh ile it will
t ranslate a computation type int o a CBN typ e, wh at will it translate a valu e ty pe
int o? The answer is: a family of C BN types {A ;} iEI. T his approach is based on
[Abramsky and McCusker , 1998].
To see the principle of t he t ranslation, we notice that in C BP V (following Prop . 27)
any value type mu st be isomorphic to a ty pe of t he form L: iEIUA i. This mo t ivat es
t he followin g.

D efinition A .7 • A eEN pseudo-valu e-typ e is a fam ily {A;} iEI of CBN ty pes.
• Let {AO;}i Elo," " {A (n- l )i}; Eln_1 be a sequence of CBN pseudo-value-types and
let {B j h EJ be another CBN pseudo-value-type. We wri t e

{AO;} iElo," " {A (n-l )i}; Eln_1 I-(:BN {(V . if ,Vy-> Hi.Ef'.
J J J
: {BjhEJ
-,-+
to mean t hat , for each io E Io, oo . , i n- I E In- I , we have V . ij E J and Vy-> is a
CBNterm Aoio, · · · ,A(n- l )in_1 1-li';-+ : B v . Y-> · We say that {(V. if, li';-+Hi.E;,. isa
J J 3 1 1
e B N pseudo-value of type {Bj hEJ on t he con tex t {AO;} iElo,"" {A (n- 1)i };EJ n_1'
Given t wo such pseudo- valu es { (V . if , Vy-> Hi'EI '. and {( W . if, W y-> Hi .EJ'. , we say
J J J ~ J ~ J -,-+
t hat t hey ar e provably equal in e B N wh en for each ij E I j we have V . ij =W . ij
and t he equation Vy-> = W y-> is provable in CBN .
J J

• Let {A O;} iElo, .. . , { A (n- l )i };El n_1 be a sequence of CBN pseudo-valu e-typ es and
let B b e a CB N ty pe. We wri t e

t o m ean that , for each io E Io, .. . ,in- l E I n- I, we have t hat M y-> is a CBN
J
t erm A Oio , " ., A (n- l )in _ 1 I- M y-> : B . We say t hat {MY->} i ' EI'. is a eBN pseudo-
1 J J J
computation of type B on the conte xt {AO;}iElo, " " {A (n- l )i}; Eln_1' Giv en two
such ps eudo-computations {My-> }i 'EI'. and {Ny-> }i 'EJ '. , we say that they are prov-
J ~ J J J

ably equal in eEN wh en for all ij E I j the equat ion M y->


J
= N y-> is provable in
J
CBN .
o
Before presenting t he reverse t rans lation , we exte nd t he forw ard t rans lat ion as
follows:
• Giv en a CBN pseudo-valu e-t yp e { A i };EI we wri te {A ;} iEJ for L: iEIUA i ·
• Given a C BN pseudo-valu e
322 CALL-B Y-PUSH- VAL UE

we write {(V. "t


J. , V~
'tJ
)}~ I t o mean t he CBPV value
tj E j

{A odi' Elo' .. . , {A(n -l)i }i'Eln _ l f-v


pm (xj) as { ... , (if , (xj)) .(V. if ,thunk Vi' ), ... } : {Bj }JEJ
J

• Given a CBN pseudo-comput ation

we write {M~ } ~
l,j 1.j E lj
to mean t he CBPV computation

It is clear that t his extende d translation preserves provable equality.


T he reverse translati on, present ed in Fi g. A. 13 is org anized as follows:
- I
• a valu e type A is translated int o a CB N pseudo-value-type An
- 1
• a com putation ty pe II is tran slated into a CB N type fl.n
• a CBP V valu e A o, . . . , A n - 1 f-v B is translated into a C BN pseudo-valu e
n- I An-I v n- I n- 1
A o , . . . , n - l f-CBN V :B
• a CBPV computat ion A o , .. . , A n - 1 f-c M : fl. is translat ed into a CB N pseudo-
. n- 1 n- 1 n- 1 n- 1
: II .
C
computation A o , . .. , A n - 1 f-CBN M
It is eas y to show that the re verse translation commutes with su bstitution (of
values) and t hence t hat it preserves provable equ ality.
Using this tran slation (and a res ult that it agrees with op erational sem an tics in
a certain sense ) we ca n ob t ain from t he printing deno tational semant ics for CBN an
alt ernative sem an ti cs for CBPV. T hus a com putat ion type will denote a family of sets
and a com putation will deno te a family of fun ctions. Mor e generally we can obt ain
a CBPV semantics from a ny CB N sem antics. Several important models, such as t he
Scot t model and the game model, can b e seen as ar ising in t his way [Abr amsky and
McCusker , 1998].
To show that t he two tran slations are inverse up to isomorphism, we firs t construct
t he isomor phisms .
1 For each CB N ty pe A we define a fun ction (lOA from CB N terms r f- M : A to
CB N t erms r f- N : Ann - I, and a fun ction (lOA 1 in t he opposit e direction .
2 For each CBPV valu e ty pe A we define a func tion (JA from C BP V valu es r f-v V :
A to values r f-v W : An-I n, and a fun ct ion (JA1 in t he opposite direction.
3 For each CI3P V computation typ e fl. we define a fun ct ion (J!i from CBP V com-
pu t ati on s r f-c M : fl. to CBPV computations r f-c N : tr:': and a fun cti on (J1/
in the oppo sit e dir ection . -
(1) is defin ed by ind uction on A . (2) and (3) are defined by mu tual induction on A
and fl.. We omit t he definitions, which are st raight for ward .

Lemma 160 (p rop er ti es of (lO and (J)


APPENDIX A: Technical Treatm ent of eBV and eEN 323

A whe re
{Q" }
{A kl h EK,I EL k

{A k Il A;}k EK,I EL

wh ere

A "- I = {A;} i EI
v V;.-I
,. wh ere
xr
let V be x . W
-+
let V~-l be x . W~~l
1,. ij k
V"
- I
• ij = k•
(V, V') (V "- I • ~
~j , V
,"-I • ;4)
~j
- 1 /n- 1
..\{O.V;'
'tj
, 1.V.,...
't
}
- I -+ •• J

pm V as (x ,y) .W W" • i j kl
-+ ••
= (k , l)
- 1 -1 - I - I
let O'Vi' be x, 1 ' ~..!'; be y. W~ .. V" . ij
ii kl
• -I' -+ ' - 1
(1. , V ) (k, V" • i j) V;'
- I -+. 'i
pm V as (Wk)" • ij I
- I -+ ••
{ , . . , (k, X)'W k," ' } let V;.- I V" • ij = (k , I)
'i
thunk M
*
- I
M ,.
M~ where
let V be x. M let Vi' be x. M!f+ k V" • ij = 1.
1 - 1 ]-1 - I - I -+ ••
pm V as ( x , y ).M let O'V;' be x , l 'V;' be y. M~ . . V" . ij= (k , l)
tj 1i ii kl
pm V as
- 1 - 1 -I -+ ••
{ . . . , (k , x).M k, . .. } l e t Vi' be x . (Mk)'h V" • ij = (k , I )
- 1 J J
force V V;'
'i
" - I -+ -I
return V (v • ij ,v;. )
- 1 tj - 1
M to x . N pm M~ as { ... , ( i , x) . N~ , ... }
Ij t jl
-I
..\x.M ..\{. .. , i ."\x.M!f+ i , .. . }
- I - I -4 - I
V 'M Vi' 'V " • ij' M!f+
J - 1 J
..\{ .. . , k .Mv , ... } ..\{.. . , k. (M k)';.. , . .. }
'" - 1 1j
1.'M k 'M~
tj - 1
print c. M print c. M~
'i

- I
Figure A .13. T he Reverse Translation -"
324 CALL-BY-PUSH- VALUE

The following equations are provable in the CBN equational theory.

OA(N[Mlx]) (o AN)[Mlx]
o Ao ::l 1M M
o::lloAM M
a B( pm M a s {... , (i , x}) .Ni , . . .}) pm M a s {... , (i , x)) .OBNi , .. .}

The following equat ions are provable in the CBPV equat iona l theory.

fJA (W[VI x]) (fJA W)[VIx]


fJ~(M [Vlx]) (fJ~M)[Wlx]
fJAfJA1V V
fJ.:tIfJA V V
fJ@i 1M M
fJilfJ~M M
fJ~ ( M to x. N) M t o x. fJ~N

fJ~( pr i nt c. N) pri nt c. fJ!l.N


(o AM)" fJ An(M")

o
These ar e each proved by induction over types . Using fJ~, we have now proved
Prop. 158(1) .
The translations are inverse up to these isomorphisms, in t he following sense:

Lemma 161 For a CBN term A o, . .. , A n - 1 f- M : B, we ca n prove in cnv


.... [OAi Xi/Xi>]
M .""-1 = OBM
For a CBPV value A o, . .. , A n - 1 f-v V : B , we ca n prove in CBPV

For a CBPV computation A o , . . . , A n - 1 f-c M : 11, we can prove in CBPV

These results can be extended to terms with holes i.e. cont ext s. o
This is proved by induction over terms using Lemma 160.
We are now in a position to prove Prop. 158(2)-(3) . Fix a CBN context A o, .. . ,A n - 1
and CBN type B .

D efinitio n A .8 For any CBPV computation U Ag, . . . ,U A~ - l f-c N : B " d efine the
CBN t er m ¢N to be
- 1 )
A o , . . . , A n - 1 f- o BN~ .... [OA; xi/x;] : B

o
APPENDIX A : Technical Treatment of CBV and CBN 325
Lemma 162 1 For any CBPV com putat ion UA 3, . . . , UA~ _1 f-c N : En , t he equa-
t ion (fjJN)n = N is provabl e in CBP V.
2 For any CB N te rm A o, . . . , A n - 1 f- M : B , t he equation fjJ (M n) = M is provable
in CB N.
o

P roof
1 - 1 )
(1) By Lemma 161, N = (3"B N" n((3u Aixi/X;] is provable, and we can see that
1n
(3"B 1 N n- [(3uA i x;jx; j = (fjJN)" by expanding both sid es and using Lemma 160.
(2) This follows directly from Lemma 161.
T his can all be extende d to te rms with holes i.e. cont ext s. 0
Prop . 158(2)- (3) follows immedi ately from Lemma 162.
Appendix B
Models In The Style Of Power-Robinson
328 CALL-BY-PUSH- VALUE

B.l Introduction
In this appendix we give ca t egorica l semanti cs for C BP V without t he st ack judge-
ment f- k. Our purpose is to prove

Propo si tion 163 The equational theory for CBPV+ stacks (Fig. 3.6) conser vat ively
extends the equat ional theory for CBPV wit hout stacks (F ig. 3.3) . This remains t rue
wh en we include the printing laws in eac h . 0

The categor ical semantic s pr esented here do es no t appear t o be a useful way of orga-
nizin g CBP V models in practic e, becau se all the mod els we have seen model st acks
in a natural way, and we would wan t t o describe t his explicitly.
As usual we first define a judgem en t model (a "st aggered Freyd ca tegory ") and
then trea t t he vari ous connect ives. We see, by means of a full reflection, that each
m odel of C BP V of this kind arises from a CBPV adj unct ion model. We see how to
generate a categorical model from a t heory, and use t his to prove t he conservation
result .

B.2 Actions of Monoidal Categories


In t his section, we review some well-known material.

D efin it io n B.9 1 A mo no idal category consists of

• a categor y C;
• a n object 1;
• a functor ® : C x C ----t C;
• natural isomorphisms

A ® (B ®C)
A

such t hat t he two st ructural isom orphisms from 1 ® 1 to 1 ar e equal and t he


d iagrams

~ ~
A ®(B ®(C ®D))

/ / 1-
(A ®B) ®(C ®D) -- «A ®B) ®C) ®D A ®B

-j
A ® «B ® C) ® D) ~ (A ® (B ® C)) ® D (A ® 1) ® B ~ A ® (1 ® B)

com mute.
2 Let (C, 1, ®) be a mon oidal ca tegory and V a ca tegory. A left C-action on V
cons ists of a fun ctor 0 from C x V to V , to gether with natural isomorphism s

A 0 (B 0 Z) (A ®B) 0 Z
Z 1 0Z
APPENDIX B : Models In The Style Of Power-Robinson 329
such that the diagrams

A 0 (B 0 (C 0 Z» ~ (A (9 B) 0 (C 0 Z) ~ ((A (9 B) (9 C) 0 Z A0 Z

-j /
A 0 ((B (9 C) 0 Z) ~ (A (9 (B (9 C» 0 Z
/j.
(A (9 1) 0 Z ~ A 0 (1 0 Z)
commute. A right C-action on TJ is defined similarly.
o
It is clear that
• every cartesian category is monoidal;
• every monoidal category has a canonical left action and right action on itself.
Proposition 164 (coherence) 1 Given a monoidal category C, every diagram
built from structural isomorphisms commutes.
2 Given a monoidal category C and a left C-action on a category TJ, every diagram
built from structural isomorphisms commutes.
o
A precise statement and a proof of Prop. 164(1) can be found in [Mac Lane, 1971].
Prop. 164(2) is stated and proved similarly.

B.3 Freyd Categories


Despite its name, the following has no connection with Freyd and is not a category
(although , as observed in [Power, 2002], it can be seen as a [. -+ " Set]-enriched
category) . We use a different, but equivalent, definition to that which appears in
[Power and Thielecke, 1999].
Definition B.10 Let C be a cartesian category and /C a category such that ob /C =
ob C-we write a morphism in /C as A f B . A Freyd category from C to /C
consists of
• an identity-on-objects functor t. from C to /C;
• a left C-action on /C, extending (along [) the canonical left C-action on C.
We call the left action x , because it is given on ob jects by x . 0
Suppose we are given a Freyd category from C to /C. We can obtain a right C-action
on /C, extending (along [) the canonical right C-action on C. This action too we call
x , because it is given on objects by x . In summary, we write! x 9 in 3 situations:
• if! and 9 are both C-morphisms, then! x 9 is a C-morphism;
• if! is a C-morphism and 9 is a /C-morphism, then! x 9 is a /C-morphism;
• if! is a /C-morphism and 9 is a C-morphism, then! x 9 is a /C-morphism.
By cont rast, if ! and 9 are both /C-morphisms, then! x 9 is not defined. So it is not
the case (in general) that /C forms a monoidal category under x .
In the sense of Power and Robinson [Power and Robinson, 1997], /C is a symmetric
premonoidal category and [ is a strict symmetric premonoidal [usicior. This provides
the definition of Freyd category in [Power and Thielecke, 1999].
A Freyd category models the 1, x-fragment of fine-grain CBV (the language defined
in Sect. A.3.2) . This means that it models computations of F type only.
330 CALL-BY-PUSH- VAL UE

B.4 Judgement Model


Whereas computat ions of F type form a category, com put ati ons of arbit rary typ e
do not , and we therefore req uire a more general st r uc t ure .
D efiniti on B.11 A stagg ered category E consist s of
• a clas s of source object s sourceob E;
• a clas s of target object s t argetob E, whose elem en ts we underline;
• a sou rce-to-target function F: so urceob E -+ targetob E;
• for eac h A E sourceob [ and Ii E targetob [ a se t [ (A ,Ii) of morphism s from A
to Ii;
• for eac h A E sou rceob E, an iden ti ty morphism A id A . FAj
• for each A f . F Band B 9 . Q, a com posit e morphism
f i9
A • Q , which we sometimes write as
f 9

satisfying ident it y and associat ivity laws


id jf f
t, id f
(f ; g ) j h t . (g; h)
o
D efiniti on B.12 Let [ be a staggered cat egory. We write [ F for t he ordinary cat-
egor y given by
sourc eob [
[(A ,FB)
with the evide nt com pos it ion . o
With t his const ruct ion [ F in mind, we ofte n write A f ' B to say t hat f
is a [-morphism from A to F B . This agr ees with t he notat ion for comp osition in
De£. B.ll.
Now we give a judgement model for CBP V (without st acks):
D efini t io n B.13 A staggered Freyd category cons ists of
• a car te sian categor y C, whose object s we call val-objects
• a staggered category [ such that sourceob E = ob C-we call the target objects of
[ com p- obj ects
• a Freyd category (~ , x ) from C t o [ F .
o
It is clear that t his mod els t he 1, x , F fra gment of CBP V (wit hout stacks) .
• A valu e type (and hen ce a context) denotes a val-object .
• A valu e r f-v V : A deno tes a C-morphism from [r] to [Al
• A com put ation typ e Ii deno tes a com p-object .
• A com put at ion r f-c M : 11 denotes a [ -morphism from [r] to [l1l
Note t hat a Freyd category can be described as a staggered Freyd ca te gory in whi ch
sourc eob E = targetob E and F is identi ty (on objects) .
A PPENDIX B: Models In The Style OJ Power-Robinson 331

B .5 Enrichment
As in Sect. 9.5.5, we define enrichment for judgeme nt models.

D e finit io n B.14 An A-set enriched staggered Freyd category is a staggered Freyd


category wh ere each homset of E is equipped with an A -set structure, and the equ a-
tions

(c*f) jg c * (fj g)
(Lf) j (c * g) C*((Lf) jg)
A x (c*g) c * (A x g)

are satisfied. o
In a similar way we can define cppo enriched and domain enriched staggered Freyd
ca t egories.

B.6 Connectives
D e finition B .1 5 Let (C, E, L, x) be a staggered Freyd category.
1 Write N for the family of left C-modules E(L - ,X] indexed by target obj ects 1':.. A
distributive coproduct for a family of C-objects {Ai h E! is a distributive coproduct
for {Aih E! in (C,N), in t he sense of Def. 9.29 and Def. 11.16 .
2 A product for a fam ily of comp-object s {~J iE! is a representing object for

rri E ! E (- ' ~i ) : Ea; -+ Se t


3 An expone ntial from a val-object A to a comp-object Il is a representing object
for
E( - x A ,Il) : E; -+ Set
item A right adjunctive for a com p-object Il in a staggered Fr eyd category (C, E, L, x)
is a representing object for

E(L- ,Il) : Cop -+ Se t

o
Pro posi t ion 1 6 5 Let (C, E, L, x) be a staggered Freyd category with all right adj unc-
tives. Then a distributive coproduct for {A ihE! in C is automatically a distributive
coproduct in (C,E,L, x). (The converse is trivial.) 0

Proof Similar to Prop. 100. 0


We can also defin e composite connectives in the manner of Sect. 9.8.1.

D efinit ion B .1 6 Let (C,E, L, x) be a stagger ed Freyd category.


1 An exponential-product for a family of val-object/comp-object pairs (A i ,Q;) is a
represent ing object for
op
II
iE!
E( - X A i , Il;) : EF -+ Se t
332 CALL-BY-PUSH- VALUE

2 A right product- adjunctive for a family of comp-objects {lIJ iEI is a represen ting
obj ect for

II
op
£(~ - ,lIi) : C -+ Se t
iEI

3 A right expone ntial-adj un ctive from a val-object A t o a comp-object 1I is a rep-


resen ting object for
£ (~ - x A, lI) : C op -+ Se t

4 An right exponential-product-adju nct ive for a family of val-obj ectj'comp-object


pairs (A i, lI;) is a representing object for

II
op
£ (~ - X A i, 1I;) : C -+ Se t
iEI

B.7 Modelling CBPV


We now corne t o our main definition.

D efinit io n B.11 A (A-set/cppo/ do main enr iched) CB P V staggered Freyd category


is a (A- set/ cppo/domain enriched) staggered Freyd cate gory with all countable dis-
tributive coprod ucts , count able products , ex ponent ia ls and right adjunctives. 0

It is easy to see how to in ter pret CBPV in such a struct ure, and we obtain a direct
model/ cat egorical model equivalence as in Chap. 10. For a CBPV obje ct structure
r , we define a r -sequent to be eit her A o, . . . , A n - 1 l-" B or A o, .. . , A n - 1 f-c 1I, wh ere
A o, .. . , A n - 1 and B and 1I are r -objects. A r -signature s provides a set s( Q) for
each T-sequ ent Q.
Given a r -signature s, we define the set of terms built from s. These ar e indu ct ively
defin ed by the rules of JWA+complex valu es, toget her with t he ru les

r f-v Vo : A o ... r f-v Vr - 1 : Ar - 1


IE s (A o, . . . , A r - 1 f-v B)
r f-v IWo ,... , Vr- I) : B
r f-v Vo : Ao . . . r f-v Vr- l : A r- 1
I E s (A o, . . . , A r - 1 f-c ll)

We take the leas t congruence ~ 8 on these te rms containing t he equationa l laws of


JWA , which as in Prop. 108 and Prop. 110 is a hy percongr uence (closed under substi-
t ution), and quoti en ting by t his congruence obtain a new signature called T's, This
gives a monad T on t he cate gory of r-signatures.

Proposi tion 166 Let r be a CBPV obj ect structure. The "categorica l semantics"
fun ct or from CBPV staggere d Freyd cate gor ies with ob ject structure T to the cat egory
of algebras for T on Sig; is an equivalenc e. 0

T his is proved in the same way as Prop. 109 and Prop. 111.
APPENDIX B: Models In The Style Of Power-Robinson 333

B.8 The Full Reflection


For a fixed CBPV type structure T , write
• Adj; for the category of (A-set/cppo/domain enriched) CBPV adjunction models
on T
• Valftrod, for the category of (A-set/cppo/domain enriched) CBPV staggered
Freyd categories on T
where, in each case, the morphisms are identity-on-objects maps preserving all struc-
ture. We will construct a full reflection (Le. adjunction whose counit is an isomorphism-
in our case, it will be the identity)

ValProd T T -.
u
--
:F
AdjT

The easy direction is the following .


Definition B.18 Suppose we have a (A-set/cppo/domain enriched) CBPV judge-
ment model A = (C,V, 0) with all left adjunctives. We obtain a (A-set/cppo/domain
enriched) staggered Freyd category.FA = (C,E ,[, x) as follows.
• The val-objects and comp-objects are as in the CBPV judgement model.
• The homsets of E are given by

• The identity on A is given by return .


9
• The composite of f.
A
F B with B
f

9
B

Furthermore, if we are given a distributive coproduct, product, exponential, or right


adjunctive in A , we obtain the corresponding structure in .FAin the evident way. 0
The harder direction is the following .

Definition B.19 Let M = (C, E, c, x) be a (A-set/cppo/domain enriched) staggered


Freyd category. We obtain a (A-set/cppo/domain enriched) CBPV judgement model
UM = (C,V, 0) with all left adjunctives as follows.
• The objects of V are the comp-objects.
• A V-morphism over A from 11 to Q is a natural transformation from E( - ,11) to
E(A x - ,Q) .
9

h h'
A A
9

h k 9
A
334 CALL-BY-P USH- VALUE

• The 0 homsets are given by

o A11 = E(A,11)
• T he comp osite of
9 h
A A

is (L(id , id)) ; h(g) .


k
• T he reindexing of ~ • 11 along A' - - --+
. A is (Lk) ; g .
• T he left adj unctive of A has ver tex FA an d return = Lid . T he required inverse of

V x( F A ,r) -t O X x Ar for all X,r


h t---+ err'
* return) ; ('Tr*h)

takes X x A ~ r t o t he natural transformation t hat at W takes


W - L - FA to (X x I) ;g.
Furthermo re , if we are given a distributive copro duct , product , exp one ntial, or right
adj unct ive in M , we ob t ain t he corresponding structure in UM in t he evide nt way.
D

Proposition 167 Let M be a CBP V st aggered Freyd category. Then:FUM =M .


D

This is st rai ghtforwar d to prove. T hus we can set the counit of our full reflection t o
be t he ident it y, while t he un it is defined as follows.

D efinition B.20 Let A = (C, V , 0) be a CBP V adjunction mod el. We define an


identi t y-on -obj ects adjunction mod el morphism A unitA. U:FA t hat
• is ide nt ity on C-morphisms and O-morphisms
h
A

takes - _ -,--9_
x
•• 11 to ('Tr' *g);('Tr*h) .
D

Finally, we have to veri fy t he triangle laws for an adj unction . Because the counit is
ident ity, these are qui te simple.
• :FunitA = idF A. This sim ply says t hat unit., is ident ity on C-morphisms , which is
true by definit ion .
• unituM = iduM . T his is easily verified .

B.9 Theories
Eac h of our equivalences between direct mod els and cate gorical mod els can be
formulat ed as an equivalence between theories and categorical models. A t heo ry is a
present ation of a direct model, sim ilar to a pr esen tat ion of a group by generators and
relati ons . We need t his formul ation for our conservat ivity result .
We present t his m at eri al for x -calc ulus, bu t it adapts straightfo rwardly to CBP V
with st acks, t o ,JWA, and, most import an tl y for our present purposes, to CBPV
withou t stacks.
APPENDIX B: Models In The Style Of Power-Robinson 335
f

ker f = {(x ,y) E A x Alfx = fy}


Definition B.21 Let r be a x object structure.
1 A theory on r for x-calculus is a r-signature 8 together with a hypercongruence
~ on terms generated from r .

2 An interpretation of a r-theory (8,~) in a direct r -modcl (1',0) is a signature


morphism 8 • r such that, writing [-]i for

T8 Ti • T1" - - -_ I r

we have
~ C ker [-]i
i.e, terms related by ~ have the same denotation.
3 A model of (8, ~) is a direct r-model (1',0) together with an interpretation i of
(8 ,~) in (1',0) .

4 A model morphism from a r-model (r,O,i) to a r-modcl (r' ,O' ,i') , of (8 ,~) is a r
.
signature morp hiIsm T f, • T suc h th a t t.; f = t.,.

Proposition 168 Let r be a x object structure, and let (s,~) be a theory on r .


There the category of models for (8 ,~) has an initial object (1', i) , and this satisfies

~ = ker[-]i

i.e, terms are related by ~ iff they have the same denotation. D

This is entirely analogous to the construction of a group from generators and relations.
It is sometimes called the classifying model of the theory.
Proof We define r to consist of equivalence classes under ~ of terms under ~ , and
obtain a quotienting map T s q • 1' . We define 0 by induction in the obvious
way, and show by induction that (Tq); 0 = J-ts j r, We define i to be TIT j q. The required
properties are straightforward. D
We now reformulate Def. B.21 and Prop. 168 using categorical models rather than
direct models.

Definition B.22 Let r be a x object structure.


1 A categorical model of a r-theory (s, ~) on r is a r-cartesian category C on r
together with an interpretation i of (8, ~) in IC .
2 A model morphism from a r categorical model (C, i) to another r categorical model
(C', i') is an identity-on-objects structure-preserving functor i F . i' such
that i; IF = i'
D

Unpacking, we see that (1) is the usual definition of categorical model , whereas (2) is
more restrictive than usual in its requirement that the functor be identity-on-objects.
This is in keeping with our fixing of object structure throughout.
336 CALL-BY-PUSH- VALUE

Proposition 169 Let T be a x object structure, and let (s,~) be a theory on T .


There t he category of categorical mo dels for (s,~) has an initial object (e ,i) , and
this satisfies
~ = ker [- ]i

i.e. terms are re lated by ~ iff they have the same denotation. o
T his is sometimes called the classifying category of the theory.

B.lO Conservativity
Propo sition 170 Let A be a (A -set/cppo/domain enriched) CBPV adjunction model.
If P is a term of CBPV without stacks (wit h printing /recursion), t hen t he denotation
of P in A is equal to the denotation of P in FA. 0

Pro p o sition 171 There is a (A -set enriched) CBPV staggered Freyd category M
such that parallel (i.e. same context and ty pe) terms P and Q (with printing) have
the same denotation if they are provably equal in t he equational theory for CBPV
without stacks (wit h printing). 0

Proof T his follows from Prop. 166 t he same way that Prop . 169 follows from Prop. 109.
o
Finally, we can achieve t he goal of the chapter: to prove Prop . 163.
Proof Let M be defined as in Prop. 171. Let P, Q be par allel terms in CBPV
wit hout stacks (wit h printing) . Suppose P and Q are provably equal in CBPV+stacks
(with printing) . T hen they have the same denotation in every adjunction model, in
particular in UM , and so (by Prop. 170) the same denotation in FUM , which is M
(Prop . 167). By the definition of M , they must be provably equal in CBPV wit hout
stacks (with printing) . 0
References

Abramsky, S. (1990) . The lazy lambda-calculus. In R esearch topics in Fun ctional


P rogram ming, pages 65- 117. Addison Wesley. (p 20)
Abra ms ky, S. (1992). Games and full complete ness for mul tiplicati ve linear logic (ex-
te nde d abstract). In Shyamasundar , R. , edit or , Pro ceedings of Foundations of Soft-
ware Technology an d Th eoretical Computer S cience, volume 652 of LNCS , pages
291- 301, Berlin , Germ an y. Springer. (p 169)
Abrams ky, S., Honda, K. , a nd McC usker , G. (1998). A fully abs t ract game seman-
t ics for general referen ces. In P roc., 13th Annual IEEE Sy mpos ium on Logic in
Com puter Sci ence. (pp 125, 169, 171, 172, 186, 193)
Ab ramsky, S., J agad eesan , R ., and Malacaria , P. (1994) . Full abstraction for P CF
(extended abstract). In Hagiya, M. and Mitche ll, J. C., editors, Th eoretical Aspects
of Computer Software. Intern ation al S ympo sium TACS '94, volum e 789 of L N CS,
pages 1-1 5, Sendai , J ap an . Spri nger-Verlag . (pp 70, 169)
Abrams ky, S. and McC usker , G. (1997) . Linearity, sharing and state: a fully abstract
game sem ant ics for Id ealized Algol wit h acti ve express ions . In O 'Hearn , P. \ V. and
Tennent , R. D ., edit ors , A lgol-lik e languages. Birkhaiiser . (p 169)
Abramsky, S. and McCu sker , G. (1998) . Call-by-value games. In Nielsen, M. and
T homas, W ., edit ors , Com pu ter Science Logic: 11th Intern ational Wo rkshop P ro-
ceedings, LNCS . Sp rin ger-Verlag. (pp xxix, 84, 175, 187, 246, 288, 289, 321,
322)
Aczel, P . (1988). Non- W ell-Foun ded S ets. Center for t he St udy of Lan gu age and
Information, Stanford University. CSLI Lecture Notes, Volume 14. (p80)
Alt enkirch , T . and Reus, B. (1999) . Mon adic presentation s of lambda t erms usin g
general ized inductive ty pes. In Flum, J. and Rodriguez-Art alejo, M., edit ors, Proc.
of 13th Int. Workshop on Compu ter Scie nce Logic, CSL '99, Mad rid , Spain , 20-25
S ept. 1999, volume 1683 of Lectu re N otes in Comput er Scien ce, pages 453- 468.
Springer-Verl ag, Berlin. (p p81, 217)
Appel, A. W . (1991) . Compiling with Con tinuati ons . CUP. (p 141)
Appe l, A. W . and Jim, T . (1989). Cont inuation-passing , closure-passing style. In Con-
f erence R ecord of th e 16th Annual ACM Symposium on P rinciples of P rogram m ing
Languages, pages 293- 302. ACM , ACM . (p 141)
Ben ton , N. and Wadl er , P. (1996). Lin ear logic, mon ad s and the lambda calculus. In
P roceedings, 11t h Annual IEEE Symposium on Logic in Computer Science, pages
420-431, New Brunswick. IEEE Com puter Society P ress. (pp xxx i, 83, 294)

337
338 CALL-BY-PUSH- VALUE

Bierman, G . M. (1998). A computational interpretation of the A/l-calculus. In Brim,


L., Gruska, J ., and Zlatuska, J ., editors, Mathematical Foundations of Computer
Sci ence, Proc, 23rd Int. Symp ., volume 1450 of LNCS, pages 336-345, Brno, Czech
Republic. Springer-Verlag, 13erlin. (p 32)
Borceux, F. (1994) . Handbook of Cat egorical Algebra 1. Cambridge University Press.
(p 208)
Ca rboni, A. , Kelly , G. M., Verity, D ., and Wood, R. J . (1998). A 2-categorical ap-
proach to change of base and geometric morphisms ii. Theory and Applications of
Categories, 4(5) :82-136. (pp 208, 262, 269, 270)
Carboni, A., Lack , S., and Walters, R . F . C. (1993). Introduction to extensive and
distributive cat egories. Journal of Pure and Applied Alg ebra, 84:145-158. (p 16)
Cockett , J . R. 13. (1993) . Introduction to distributive cat egories. Mathematical Struc-
tures in Computer Sci ence, 3(3):277-307. (p 16)
Curien, P.-L . (1998). Abstract Bohm trees. Mathematical Structures in Computer
Science , 8(6) :559-591. (p 174)
Curien, P.-L. and Herbelin, H. (2000) . The duality of computation. In Proc ., ACM
Sigplan International Conference on Functional Programming (ICFP-OO), volume
35.9 of ACM Sigplan Notices, pages 233-243 , N.Y . ACM Press. (p 288)
Danos, V., Herbelin, H., and Regnier, L. (1996). Game semantics and abstract ma-
chines. In Proceedings of the Eleventh Annual IEEE Symposium On Logic In Com-
puter Sci ence (LICS '96), pages 394-405, New York. IEEE Computer Society Press.
(pp173,174)
Danos, V. and Regnier, L. (1999) . Reversible, irreversible and optimal A-machines.
Th eoretical Computer Sci ence, 227(1-2):79-97. (p 173)
Danvy, 0 . (1992) . 13ack to direct style. In ESOP '92, Proc . Europ ean Symposium
on Programming, R ennes, volume 582 of LNCS, pages 130-150. Springer Verlag.
(pp 141, 142)
Duba, B., Harper, R ., and Macqueen , D. (1991) . Typing first-class continuations in
ML . In ACM-SIGACT, A.-S ., editor, Conference Record of th e 18th Annual ACM
Symposium on Principles of Programming Languages (POPL '91) , pages 163-173,
Orlando, FL , USA. ACM Press. (pp 96, 150)
Felleisen, M. and Friedman, D. P . (1986) . Control operators, the SECD-machine,
and the A-calculus. In Wirsing, M., editor, Formal Description of Programming
Conc epts, pages 193-217. North-Holland. (pp xxxviii, 27, 32)
Filinski, A. (1996). Controlling Effects. PhD thesis, School of Computer Science,
Carnegie Mellon University, Pittsburgh, Pennsylvania. (pp xxii , xxxi, xxxii)
Fiore, M., Plotkin, G . D., a nd DrTuri (1999). Abstract syntax and vari able binding. In
Longo , G ., editor, P roceedings of th e 14th Annual Symposium on Logic in Computer
Science (LICS '99) , pages 193-202 , Trento, Italy. IEEE Computer Society Press.
(pp81 ,217)
Freyd, P. J . (1991) . Algebraically complete ca tegories. In Carboni, A. et aI., edi tors,
Proc, 1990 Como Category Theory Conference, pages 95-104, Berlin. Springer-
Verlag. Lecture Notes in Mathematics Vol. 1488. (pp 72, 74)
Friedman, H. (1978) . Classically and intuitionistically provably recursive functions . In
Muller, S., editor, Higher Set Theory, volume 699 of Lecture Not es in Math ematics,
pages 21-28. Springer-Verlag. (pp 142, 158)
Ghica, D . R . (1997) . Semantics of dynamic vari ab les in algol-like languages. Master's
thesis, Queens' University, Kingston ,Ontario. (pp xxxix, 125, 136)
Girard, J.-Y. (1987) . Linear logic. Th eoretical Computer Science, 50:1-102. (p xxxi)
REFER EN CES 339

Gir ard, J .- Y , Lafont , Y., and Taylor , P. (1988). P roofs an d Types. Ca mbridge Tr acts
in Theoreti cal Computer Science 7. Ca mbridge Univers ity Press. (pp 7, 158)
Goguen , J ., That cher , J ., and Wagn er , E . (1979). An ini ti al algebra approach to t he
specification, correct ness , and implem entation of abstract dat a typ es. In Yeh , R .,
edito r , Current Trends in Programming M ethodology IV, pages 80-149. Prent ice-
Hall. (p 83)
Griffin , T . G . (1990). The formulae-as-typ es notion of control. In Conf. R ecord 17th
Annual ACM Symp. on P rinciples of Program m ing Languages, P OPL '90, San
Francisco, CA , USA , 17-19 Jan 1990, pages 47- 57. ACM Press, New York. (pp 142,
158)
Gunt er , C . A. (1995) . S emantics of P rogram m ing Languages. MIT P ress. (p xxix)
Harmer , R . and McC usker, G . (1999) . A fully a bstra ct ga me semantics for finit e non-
determinism . In LICS : IEEE Sy mp osiu m on Logic in Computer Science. (p 169)
Hatcliff, J . and Dan vy, O . (1997). Thunks and t he A-calculus. J ourn al of Fun ctional
Programming, 7(3) :303- 319. (ppxxx, xxxi, 20, 151, 312)
Hennessy, M. C . B. (1980) . The semanti cs of call-by-valu e and call-by-name in a non-
det erministic environment. SIAM Jo urnal on Computing, 9(1):67- 84. (pxxix)
Hennessy, M. C. B. and Ash croft , E . A. (1980) . A m athema ti cal semantics for a nonde-
te rm inist ic ty ped lambda -calculus. Th eoretical Computer Sc i ence, 11(3):227- 245.
(p 20)
Hofm an n , M. (1995) . Sound and complete ax iomatisations of call-by-value cont rol
operators . Mat hematical St ructures in Computer Scienc e, 5(4):461-482. (p 238)
Hofmann, M. and St reicher, T . (1997) . Cont inuation models ar e universal for AJ1o-
calculus. In Proc., T welfth A nnual IEEE S ym posium on Logic in Compu ter S cience,
pages 387- 395, War saw , Pol and. IEEE Comput er Society Press. (pp 103, 151,
158)
Honda , K. and Yoshida, N. (1997). Game theoreti c ana lysis of ca ll-by-value com -
pu t ati on . In Degan o, P. , Gorrieri , R. , and Marchet ti -Sp accarn ela , A., edit ors, Au-
tom ata, Languages and P rogram m ing, 24th Intern ational Colloquium, volume 1256
of L N CS , pages 225-2 36, Bologna , It aly. Springer- Verl ag. (pp xx ix , 175)
Hu th, M., J ung , A., and Keim el, K. (2000). Linear types and ap proximation . Math .
S tru ct. in Compo Scienc e, 10:719- 745. (p 110)
Hyland, J . M. E. and On g, C.-H. L. (2000). On full abstract ion for P CF : I, II , and
III. Information an d Computation, 163(2):285- 408. (pp xx ix , 47, 66, 169, 174,
175, 176, 201)
Ing erman , P. Z. (1961) . Thunks: A way of com piling procedure stat eme nts with some
comme nts on pro cedure declarations. Com m unica ti ons of the A CM, 4(1) :55-58.
(p xxxiv)
J acobs, B. (1999) . Cat egoria l Logic and Type Th eory. Elsevier , Am st erdam . (p 268)
J effrey, A. (1999) . A fully abstract semantics for a high er-order fun cti on al lan gu age
wit h nondet erminist ic comput at ion. T CS: T heoreti cal Computer S cien ce, 228. (p 251)

Jung , A. (1990) . Colim its in DCPO . 3-page manuscript , available by fax . (p 136)
Kri vin e, J .-L. (1985). Un interprct eur de A-calcul. Unpublished . (p32)
Krivine, J .-L . (2001). person al com munication . (p 54)
Lafont , Y ., R eus, B., and Streicher , T . (1993). Cont inuation semant ics or expres sing
implicati on by negati on . Techni cal R ep ort 9321, Ludwig-Maximilian s-Universit at ,
Miinchen . (pp 142, 158)
340 CALL-BY-PUSH- VALUE

Laird, .I. (1997) . Full abstraction for functional languages with control. In Proceedings,
Twelfth Annual IEEE Symposium on Logic in Computer Science, pages 58-67,
Warsaw, Poland. IEEE Computer Society Press . (pp 20, 169)
Laird, .I. (1998) . A S emantic Analysis of Control. PhD thesis, University of Edinburgh.
(p 103)
Laird, .I. (2003) . A categor ical semantics of higher-order st ore. In Proc., 9th Con-
ferenc e on Cat egory Th eory and Computer Science, Ottawa, 2002, volume 69 of
El ectronic Not es in Theoretical Computer Sci ence. (p 171)
Lambek, J . and Scott, P. (1986) . Introduction to Higher Order Categori cal Logic.
Cambridge Univ ersity Press, Cambridge. (p 235)
Landin, P. J . (1964) . The mechanical evalua tion of expressions. The Computer Jour-
nal, 6( 4) :308~320 . (p 32)
Landin, P. J. (1966) . The next 700 programming languages. Communications of th e
A CM , 9(3) :157~ 164. Or iginally presented at the Proceedings of the ACM Program-
ming Language and Pragmatics Conference, August 8-12 , 1965. (pxxii)
Laurent , O. (1999) . Pol ari zed proof-nets: proof-nets for LC (extended abs tract) . In
Girard, .I.-Y ., edit or, Typed Lambda Calculi and Applications '99, volume 1581 of
Lecture Not es in Computer Sci ence, pages 213-227. Springer. (pxxxi)
Laurent, O. (2002a) . Etude de la polarisation en logique. PhD thesis, Universite Aix-
Marseille II. (p 175)
Laurent, O . (2002b) . Polarized games. In Logic in Computer Sci ence, pages 265-274,
Los Alamitos, CA , USA. IEEE Computer Society. (p 174)
Lawvere, F . W . (1963) . Functional S emantics of Algebraic Theories. PhD thesis,
Columbia University. (p 216)
Levy, P. B. (1996) . A-cal culus and cartesian closed categories. Essay for Part III of
the Mathematical Tripos, Cambridge University, manuscript. (p 251)
Levy, P. B. (2001). Call-by-push-valu e. PhD thesis, Qu een Mary, University of London.
(p xxi)
Levy, P. 13. (2002) . Possible world semantics for general storage in call-by-value. In
Bradfield , J., edit or , Proc., 16th Annual Conference in Computer Science Logic,
Edinburgh, 2002, volume 2471 of LNCS, pages 232-246. Springer. (pp xxxix,
126)
Levy, P. B. (2003) . Adjunction models for call-by-push-value with stacks. In Proc., 9th
Conference on Category Theory and Computer Science, Ottawa, 2002, volume 69
of Electronic Notes in Th eoretical Computer Science. (p xxii)
Levy, P. B., Thielecke, H., and Power, A. J. (2003). Modelling environments in
call-by-value programming languages. Information and Computation, 185 :182~21O .
(p 287)
Longl ey, J. and Plotkin, G. (1997). Logical full abstraction and PCF. In Ginzburg,
J., editor, Tbilisi Symposium on Languag e, Logic and Computation. SiLLI/CSLI.
Also available as LFCS Report ECS-LFCS-97-353 . (p 169)
Mac Lane, S. (1971) . Cat egories for the Working Math ematician , volume 5 of Graduat e
Texts in Mathematics. Springer-Verl ag , New York . (pp24, 236, 237, 264, 284,
329)
Marz, M. (2000) . A Fully Abstract Model for S equential Computation. PhD thesis,
Technische Universitat Darmstadt. published by Logos-Verl ag, Berlin. (p xxxi)
Marz, M., Rohr, A., and Streicher, T . (1999) . Full abstraction and universality via
realisability. In LICS: IEEE Symposium on Logic in Computer Sci ence. (p xxxi)
McCusker, G. (1996) . Games and Full Abstra ction for a Functional Metalanguage
with R ecursiv e Types. PhD thesis, University of London. (pp 80, 174, 176, 179)
REFERENCES 341

McC usker , G . (1997). Games and definabili ty for FPC. Th e Bulletin of S ym bolic
Logic, 3(3):347-362. (p 169)
Moggi, E . (1988) . Computational lambda-calculus and mo nads. LFCS R eport ECS -
LF CS-88-66 , University of Ed inburg h . (pp xxxi, 18)
Moggi, E . (1991). Notions of computation and mon ads. Inform ation and Compu tation,
93:55-92. (ppxxii, xxv iii, xxxi, xx xii , 14, 18, 20, 89, 90, 114, 216, 293, 307)
Moggi, E. (90) . An abstract view of pr ogramming lan gu ages. Technical Rep ort EC S-
LF CS-90-113 , Dept. of Com puter Science, Edinburgh Univ . (pp xx ix, 125, 136)
Murthy, C. (1990) . Extracting Cons tructive Cont ent f rom Classica l Proofs. PhD t hes is,
Cornell University, Dep ar tment of Comput er Science. (p 158)
Nickau, H. (1996 ). Heredita rily S equent ial Funct ionals: A Gam e-Theoretic Approach
to S equentiality. Sh aker-Verl ag. Disser t ation, Univers itat Gesamt hochschule Siegen.
(pp xxix, 169)
Odersky, M. (1994) . A fun ction al theory of local names. In ACM , editor, Proceedings of
21st Annual ACM SIGACT-SIGPLAN Symposium on Pr in ciples of Programming
Languag es (POPLj, pages 48-59 , New York , NY , USA. ACM Press. (p 137)
O 'Hearn, P. W . (1993). Op aque ty pes in algol-like lan gu ages. manuscript . (pp 90,
116)
O 'Hearn, P. W . and Tennent , R. D. (1995). Parametricity and local variables. Journal
of th e A CM, 42(3):658- 709. (pp 136, 137)
Oles, F . J . (1982). A Category- Theoretic A pproach to th e Semantics of Programming
Languages. Ph. D. dissert ati on , Syracuse University. (pp xxix, 125, 136)
On g, C. H. L. (1988) . Th e Lazy Lambda Calculus: A n Investigation int o the Foun-
dations of Functional P rogram m ing. PhD t hesis, Imperi al College of Scienc e and
Technology. (p 20)
On g, C.-H. L. (1996). A semantics view of classical pro ofs: type-theoretic, categorical,
den otati onal characterizations. In Proc, 11th IEEE Annual S ymp osium on Logic
in Compu ter Science, pages 230-241. IE EE Com puter Soc iety Press. (p 160)
Pari got , M. (1992). AJL-calculus: An algorit hm ic interpretati on of classical natural
deduction . In Voronk ov, A., edit or , Proceedings of th e Intern ational Confe rence on
Logic Programming an d A ut omated R easoning (LPA R'92j, volume 624 of L NAI,
pages 190-201 , St . Peter sburg, Ru ssia. Springer Verl ag. (p 160)
Park , D. (1968) . Som e sem antics for data struct ures. In Michie, D., edit or, Ma chin e
Int elligence 3, pages 351-371. American Elsevier, New York. (pxxxiii)
Pi t ts , A. M. (1996) . Relational properties of domains. Info rm ation and Computation,
127:66-90 . (pp69 , 74, 76, 140)
Pi tts, A. M. and Stark , 1. D . B. (1993). Obs ervable properties of higher order fun ctions
that dynamically create local names , or : What 's new? In Math ematical Foundations
of Computer Science, P roc, 18th Int. Symp ., Gdansk, 1993, volume 711 of LNCS ,
pages 122-141. Springer-Verl ag, Berlin. (p 125)
Pl otkin , G . D. (1976). Call-by -name, call-by-value and t he A-calculus. Th eoretical
Compu ter Science, 1(1):125-1 59. (pp xxxi, 20, 150, 151)
Pl otkin , G. D . (1977). LCF as a pro gramming lan gu age. Th eoretical Compu ter Sci-
ence, 5. (pp xx viii, 20, 47)
Pl otkin, G . D. (1983) . Dom ains. 1992 TeXe d editi on of course notes prepared by Yugo
Kashiwagi and Hid etaka Kondoh from not es by Ta tsuya Hagin o. (p 84)
Pl otkin , G. D. (1985) . Lectures on predom ain s and partial functions. Course notes,
Center for t he St udy of Lan guage and Informati on , Stanford . (pp xxviii, 13)
342 CALL-BY-PUSH- VALUE

Plotkin, G. D. and Power, A. J . (2002) . Notions of com put at ion determine mon-
ads . In Proc., Foundations of Software Sci ence and Computation Structures 2002,
Grenoble, France , volume 2303. LNCS. (pp 260, 294)
Power (2002) . Premonoidal categories as categories with algebraic structure. Theoret-
ical Computer Science, 278(1~2) :302~331. (p 329)
Power, A. J. and Robinson, E . P. (1997) . Premonoidal categories and notions of
comput at ion . Math . Struct. in Compo Sci ., 7(5) :453-468. (p 329)
Power, A. J . and Thielecke, H. (1999) . Closed Freyd- and kappa-categories. In Proc,
ICALP '99, volume 1644 of LNCS, pages 625-634. Springer-Verlag, Berlin. (p 329)

Reynolds, J. C. (1981) . The essen ce of Algol. In de Bakker, J . W . and van Vliet,


J . C. , editors, Algorithmic Languag es, pages 345-372, Amsterdam . North-Holland.
(pp 46, 125)
Sabry, A. and Felleisen , M. (1993) . Reasoning about programs in continuation-passing
style. Lisp and Symbolic Computation, 6(3/4) :289-360. (pp 141, 142, 161)
Sangiorgi, D. (1999) . Interpreting functions as pi-calculus pro cesses : a tutorial. RR
3470, INRIA Sophia-Antipolis, France. (ppxxx, xxxi)
Sazonov, V. Y. (1976) . Expressibility of functions in D. Scott 's LCF language. Alg ebra
i Logika , 15(3) :308-330 . Translation. (p 47)
Scott, D. S. (1982) . Domains for denotational semantics. In Nielson, M. and Schmidt,
E. M., editors, Automata, Languages and Programming: Proceedings 1982. Springer-
Verlag, Berlin. LNCS 140. (p 80)
Selinger, P. (2001) . Control categori es and duality: On the categorical semantics of the
lambda-mu calculus. Mathematical Structures in Computer Sci ence, 11(2) :207-260.
(pp 261, 288)
Simpson, A. K. (1992) . Recursive types in Kleisli categories. Unpublished manuscript .
(p 24)
Smyth, M. and Plotkin , G. D. (1982) . The category-theoretic solution of recursive
domain equations. SIAM J . Computing, 11. (pp 69, 70, 86)
Stark, I. (1996). A fully abstract domain model for the rr-calculus. In Proceedings of
the Eleventh Annual IEEE Symposium on Logic in Computer Sci ence, pages 36-42 .
IEEE Computer Society Press. (p 70)
Stark, I. D. B. (1994) . Names and Higher-Order Functions. PhD thesis, University of
Cambridge. (pp xxix, 125, 136)
Steele, G. L. (1978). RABBIT: A compiler for SCHEME. Technical Report 474, Arti-
ficial Intelligenc e Laboratory, Massachusetts Institute of Technology, Cambridge,
MA . MSc Dissertation . (pp xxxix, 141, 142)
Stoltenberg-Hansen, V., Lindstroem, I., and Griffor, E. R . (1994) . Mathematical The-
ory of Domains. Cambridge University Press, Cambridge, 1 edition. (pp84,
85)
Streicher, T . and Reus, B. (1998) . Classical logic, continuation semantics and abstract
machines. Journal of Functional Programming, 8(6) :543-572 . (ppxxix, 32, 90,
103, 116, 288)
Tait , W . W . (1967) . Intensional interpretation of func tionals of finit e type I. Journal
of Symbolic Logic, 32(2) :198-212 . (pp 30, 67, 134, 153)
Tennent, R . D . and Ghica, D. R. (2000) . Abstract models of storage. High er-Order
and Symbolic Computation, 13(1-2) :119-129. (pxxxiii)
Thielecke, H. (1997a) . Cat egorical Structure of Continuation Passing Style. PhD the-
sis , Universit y of Edinburgh. (pp 103, 141, 142, 149, 151)
REFERENCES 343

Thielecke, H. (1997b) . Continuation semantics and self-adjointness. In Proceedings


MFPS XIII, Electronic Notes in Theoretical Computer Science . Elsevier. (pp 226,
261)
Wadler, P. (2003) . Call-by-value is dual to call-by-name. Proceedings, 8th ACM SIG-
PLAN International Conference on Functional Programming, Uppsala, Sweden , to
appear. (p 288)
Wadsworth, C. P. (1976) . The relation between computational and denotational prop-
erties for Scott 's D oc-models of the lambda-calculus. SIAM Journal on Computing,
5(3) :488-521. (p 20)
Index

* (concatenation of strin gs), 8 I--+cg 309


$, xxxii I--+cg~al 309
L, ;~IE $ ri , 300
I--+Iazy , '313
,
n:;~E $ ri 301
I--+Iazyval, 313
r (arena op eration ), 177 , 196
L (de lim it s se veral argu me nts) , 301 r (thread ) , 191
\ (co m p osit ion), 191 ':::', see ob ser va ti on al equ ivalence
f3 -1aw, 6, 53, 59, 163 x -ca lculus , 216, 249
... (whe re we are now ) , 145 10 as a co m p ut at ion ty pe , 79
1- as a term , 78 f- in an are na, 177
1- as a value ty pe , 79 f-c 29
• (d ismantli ng a stack), 36 f-< 33
• (gluei ng righ t modul e) , 269, 270 f-n, 143
CAB , 21O f-P , 305
N A , 210
*
f-v, 29, 143 , 305
(co ncatenation of stacks), 36 * (co m posit ion), 210
:: (stack formation ), 33 xM (weakeni ng) , xxxiii, 98
-r: (stack forma tion ), 98 , (a p plicat ion backw ards ), xxxii
l±I (d isjoint union of a re n as), 177 j (seque nc ing of co m mands ), 46
o (empty arena) , 177 j (com pos it ion in di agr ammatic order ),
l1-exp an sion, 188 xxxii
l1-law , 6, 26, 51, 53, 59, 151 , 163, 312 = : (assignme nt ba ckwards) , 180
<lfin, 78, 79 , 179 "" (empty st ring), 8
'Y (po int in J W A) , 143
'1, 28 A (set of print able cha racte rs), 8
Ac-calculus, xx xi, 18 A* ,8
'-+ ,72 A-set , 3 , 21
let , 4 free , 21
9 ASe t , 132 , 225
A
A-set enr iched, see enr iched
ab stra ct m at er ial , 207
accept able in finit ely d eep t erm , 77 , 78
action
left , 328, 329
righ t , 329
ad equacy
cell ge ne ration + d iver gen ce , 134
er ratic choice, 108
infi nit ely deep t erms, 79
infin it ely deep ty pes , 79

345
346 CA LL-B Y-P USH- VALUE

point er games, 194, 195 Cp , 269, 270


recursion, 67 C-mach ine, 151-154
recursive ty pes, 76 wit h printi ng, 153
thunk storage, 140 calculus
adj oint )..bool +,4
left, 235 xE D -t, 61 , 143
right , 235 x
adj unction , 235 , 278-286 direct model, 253-254
ad missible s ubcategory, 72 semantics of ty pes, 250
ad m issib le su bset, 67 jumbo A, see j um bo A-ca lcu lus
a lgebra for monad, 2 13, 236, 283 call- by-name , xxix , 9, 18-25, 311
d en ot ed by C BN ty pe, 24-25 eq uat iona l t heory, 311
d en ot ed by com p utation type, 41 call- by- need , xx ix, 20
d irect mo del as, 253 ca ll-by-push (anothe r name for C B N), 54
exponent ial, 25 ca ll-by-pus h-va lue, 27-336
free, 24 reas on for name, 54
homomorphism denoted by stack, 41 ca ll-by-value, xx ix, 9- 18
produ ct , 25 coarse-g rain, 17, 304, 30 8~3 1O
via alg ebraic op erations, 294 equational t heo ry, 307
a lgeb raic op er ation , 260 , 294 fine-gr ain , 18, 305- 310
Ans in conti nuation sem ant ics , 101 carrier
Ans in cont inua ti on sem ant ics, 105 of A-set , 21
answer-mo ve , 195 of a lgebra, 24
answer- mo ve pointing t o an swer-move, CartCat, ,251
197 Cat, 216
arena, 174 category
d efin it ion of, 176 bicart esian closed, 17, 26, 63
Q/ A-la belled , 195 bilim it-com pact , 70, 85, I l l, 140
stackfree-in-stack, 199, 248 cartesian , 15 , 250
stackfree-in-val ue, 199, 248 cartesian clos ed , 23 , 26, 83
uni versa l, 174 coun tably dist ribut ive, 237
ArenaIso, 177, 190 distributive, 16, 63
a rity of operation symbol, 251
enriched , 70
assignment , 91, 118 Kleisli for a monad , 15
monoid al , 328
S ohm tree, 77
su b- bllimit-compact , 72- 73, 85, 111
bad cells, 172
value, 63
Beck-Ch evall ey condition, 281
CBN , see ca ll-by-na me
beh av iours
CBN adj unction mod el , 287 , 289
com p utation ty pe d en ot es set of, 92,
C BPV, see ca ll-by -pus h-value
107, 126
C BPV adjuncti on mod el , 234
big -step sem a nt ics
for C BN, 19 C BPV judgem en t mod el , 222
for CSP V , 31 CSPV pr e-families mod el, 247
with cell gen eration, 121 CS V, see ca ll-by- value
with erratic choice , 107 CBV adj unction m od el, 287, 290
with global st ore, 92 cell , xxx iii, 91, 117
wit h printing, 38 cell gene ration, 117- 140, 171,1 92
for C S P V erro rs, 112 cell ty pe , 122
for C BV, 10 changestk , 95
unsui t able for cont ro l effect s, 95 CK-machin e, 32-37, 52-54, 95- 102, 154
bilimit , 70 wit h prin ting , 38
bimodu le, 209 clas sical logic, 157-160
bracketable ga me, 200 classify ing category, 336
bracketed move, 200 classify ing model, 335
bracketing con d ition, 171, 202 , 248 co-Kleisli
strong adj u nction, 286
co-Kleisli adjunct ion, 284
INDEX 347

co-Kleisli part , 285 Cpo , 13


of a strong adj unct ion, 286 , 287 cpo , 13
cocone, 70 pointed, 22
code jumpabout., 145 Cpo-r (cppos and strict con tinuous fu nc-
coerce , 46 tions) , 70, 71
coherence, 254 cpo semantics,
of monoidal categories and actions, seeScott semantics13
329 cppo, see cpo, pointed
coinduction, 81 cppo enriched, see enriched
comm, 136 staggered Freyd category, 331
command, 46, 136 CPS transforms, 149- 151
as prefix , 8, 118 current stack, 95
nonreturning, see nonreturning com- currying, 61
mand,97 cusl, 84
comp-object, 222 , 254, 330
comparison functor , 235 data of a jump, 176
compatible relation , 78 decomposition
complete lattic e, 108, 111 +C B N into CBPV, 44
complex stacks, 58 --+CB N into CBPV , 44, 104
complex values, 50-51, 119 --+CB N into linear logic, 294

eliminabi lity of, 54 --+CBV int o CBPV, 42


--+ C B V into monadic metalanguage,
in CBV, 307
in J ump-With-Argument, 155 294
definability
compositionality, 83, 102
po inter games, 194
computability, 66
dependent types , 296-297
computation , xxxiv
descended evenly, 185, 193
computation type , xxxvi
descended oddly, 184, 193
computation-unaffecting, 47, 49, 164
det erm inist ic strategy, 185, 187
computational A-calculus, see Ac-calculus
dinatural, 130
computational effects , see effects
Dir-ectv , 253
computations
direct model
categorical semantics of, 222
for x-calculus, 253-254
concatenation of stacks, 36, 58, 221
direct model/categorical model equiva-
formal defini tion , 256 lence, 249-260
configuration, 152 dismantling a stack, 36, 37 , 58, 222
of C-machine for JWA, 152 formal definition, 256
of CK -machine, 32, 35 distribut ive coproduct, 16, 218
of CK -machine with control, 98 in CBPV j udgement model , 232
conservative extension , 59 in JWA judgement model, 231
contents of cell , 120 with left modules, 231, 273
context (list of typed identifiers), 28 diverge, 67
context (term with hole) , 17, 18 divergence , xxviii, 65
context extension, 263 with cell generation, 133-135
context morphism, 216 domain , 83, 289
continuation, 32, 36, 103 domain enriched , see enriched
continuation semantics, see con trol ef- staggered Freyd category, 331
fects, 101-106, 238 domain equation, 69, 139
continuation-passing-style, see StkPS D omStr (do mains and strict continuous
continuous function, 13 functions) , 83, 225
control effects, 95- 106, 171 duality
combined with other effects , 105- between CBV and CB N, 288
106 between values and stacks, 98, 104,
control flow, xxxvi , 148, 195 239, 288
coproduct-jumpwith , 190, 243, 246 , 265
copycat, 188, 190, 193 E-set, 113
copycat , 190 edge in multigraph, 251
counit of adjunc tio n, 235 effect -free language, 216
348 CALL-BY-PUSH- VALUE

effect s, xxviii fun ctor


Eile nbe rg-Moore , 213, 236 , 283 , 294 cont ravaria nt , d en ot ed by com p uta-
element style definit ion , 16, 265 , 267 ti on ty pe, 129, 131
em pty stack, 98 cova riant, denoted by value ty pe,
end , 295 124
enriched locall y cont inuous, 73
in [Cop, S e t ], 211
in Cpo, 67 globa l m orphism , 211
j udg ement model, 190 globa l representing object, 267
j udg ement models , 223 , 260 global st or e, 91-95, 241, 296
st aggered Fr eyd category, 331 Gr othendieck const ru ct ion , 264
envi ro nment, xxx iii gr ou nd context, 17, 18, 39
(e, p) -pair, 70 in JWA, 155
equa lity t esting of cells , 118 gro und returner , 13, 29
equat ional theor y ground t er m, 22
CBP V + cont ro l, 162 ground type, 4, 29 , 301
CBP V with st acks, 58 ground value, 29
CBP V without st a cks, 51-52, 328 grow , 264
for CB N , 311 growa ll,264
for C B V , 307 growhom x CN , 272
for JWA, 155-156
errat ic cho ice, 107~ 109, 239
head normal form , 20
finit e, 109, 294
hom, 209, 214
errors , 111-11 4
hom x c , 268
evaluat ion cont ext , 32
hom x cN , 272
except ion handling, 46, 111
hom 0 1J , 269 , 270
exponent ial, 16, 218, 265
homom orphism
in C BP V judgem ent m od el, 230
betw een A-sets, 4 1
in staggered Fr eyd ca te gory, 331
bet ween alg eb ras, 4 1
Kleisli, 17,237
of E -sets , 114
with right modules, 229 , 271
homset fun ct or , 209 , 2 14
ex ponent ial-prod uct , 265
hyper- ari ty, 300
in staggered Freyd ca tegory, 331
hyp ercon gruence, 252, 257
wit h ri gh t m odules , 271

Fs, 138 I (categorica l semantics) , 253


families id eal , 110, 111
of ar enas , 175, 178 Id ealiz ed Algo l, 136
families const ruction, 243- 248, 288-290 idempotent s split, 237 , 284
fglow, 110 ide nt ifier, xx xiii
fibr e of locally ind exed ca tegory, 211 ignor ed , 46
finit e a pp rox imant , 78, 79, 179 -ignor ed, 161, 167
finit ely generate d lower set, 110 in cl ude d in a st rategy, 185
f old, 69 indexed ca tegory, 211
forc e as jump, xxxvi, 148, 195 ind ifference theor em , 151
forcing a thu nk, xx xiv infin it e play, 185, 187
for est, 176 infinit ely deep sy ntax , 77-82, 140
Freyd cat egory, 329 infinitely wid e sy ntax, xxxv i, 65, 132
full abstract ion ini tial object
of po inter ga me mod el, 171, 194 distributi ve, 17
of tran slation fro m CBN to C B PV, initi ali za ti on , 118, 121, 192
xxxi i, 320 innocence , 174
of trans la t ion from CBV to CBPV, innocen ce condition , 171
xxx ii, 3 14 input , 90 , 294
fu ll com plete ness, 169 int era cti on sequ ence, 191 , 193
full reflection, 333 int erpret at ion of a theory, 335
fu nct ion ty pes in j um bo A-calcul us, 301- invar ia nt
302 for fu nctor, 73
INDEX 349

invisib le const r uc t s , 40 , 45 lIuf subcategory, 72


thunk and fo r ce, 42 lo cally continuous, 73 , 75 , 138
isomorphism of arena families, 178 locally index ed
isomorphism of arenas , 177 functor, 212
Qf A-resp ect ing , 196 natural t ransformat ion, 216
locally indexed cat egor y, 211
j (isomorphism), 277 locall y indexed functor , 212
join-sernilattice, 111 log ic
joint naturality, 262 classical, 157-160
judgement model in tuitionist ie, 26, 158
CBPV, 222 linear, xxxi, 110 , 173,295
JWA ,220 drawbacks of decomposition , 295
Jumbo A-calculus, 300-302 lower powerdomain , 110
jump, xx xvi , 143
jump-point , 103 , 143 may-testing equivalent , 109
Jump-With-Argument, 141-168, 295 metalanguage, CBPV as a , 45, 94 , 105
as type theory for classical logic , min imal invariant, 138
157-160 for funct or , 73
C -machine , 151-154 mkpseudo , 172
with printing, 153 m od el morphism , 335
dependent types, 296 model of a theory, 335
em be d d ing into CB PV + Ans , 144 module
eq ua t ion al t heory, 155 left , see left module
graphical syntax , 144 right, see right module
jumping machin e, 145-1 48, 154 monad ,235
polym orphic types, 297 definition of, 15
j umpabout , 145 drawbacks of decomposi tion, 294
code, 145 lifti ng, 17
trace, 145 printing, 17
semantics for CBV, 17
jumping implementation
strong, 15, 24, 114
of CBPV, 148
Ton MGraph r , 252 , 255
j umping machine, 145 -148, 154
monadic m et al a nguage, xxxi , 83 , 294 , 307
jumpwith , 226, 265
move , 174
j ustified sequence, 184
m ove with pointer, 183
JWA, see Jump-Wit h-Argument
move without pointer, 183
J WA judgement model , 220
multicusl, 84
J WA module model , 234
multigraph, 25 1
JWA pre-families model, 246
N (set of cell types), 122
ky , 269 , 270 N A , 2 1O
kernel,335 Ne, 232
Kl eisli , 236
strong adj u nc t ion, 285
»: 232
nat , 65
Kleisli adj unction, 284 naturality
Kleisli exponential , 17, 237 joint vs . separate, 262
K leisli part, 284 naturality style definition, 265 , 267
of a strong adjunc t ion, 286, 287 negation
K leisli produc t, 237 classical, 157
new, 118
la zy, 20 , 312-314 newrec , 193
lef t adj unct ive, 227 , 267 newrec , 118 , 193
left coprod uct-adjunctive, 244, 247, 267 nil , 33, 98
left modu le, 190, 208 , 220 nil P , 98
letstk, 95 no thunk storage, 123
LICat, 216 non-closed
lift ,23 CBPV computation, evaluation of,
lift -reflecting, 67 33
350 CA LL-BY-PUSH- VALUE

JWA co m m a nd , evaluat ion of, 143 P layer- move, see P- m ove


non return ing command , 46, 180 pm (pattern-match), 4
nonret urnin g commands PO- bracketed p lay, 201
categorical sem ant ics of, 220 p oint
non returning-com mand ga m e , 183 code, 145
nonreturning-command p lay, 185 trace, 145
nonretu rning- co mmand strategy, 185 poi nted cpo, see cp o, p oin t ed
nSt rat , 185 pointer ga m e sem ant ics , 1 6 9~2 03 , 246 -
248,296
O-m ove , 182, 185 , 187 prob lem s with , 169
obj , 210 po intwise id eal opbi mod ule , 240
object pol ari ty, xxx i, 174
ce ll re prese nte d as, 171 po lymorph ism , 29 7
object struc t ure pop , xxxiii, 33
x , 250 possible wo rl ds, 117- 140 ,241,277
C B P V, 254 p owerdom ai n
JWA ,259 lower (H oare), 110
o bse rva t ional eq u iva lence pre-fa milies m od el
for C BN a nd lazy, 18 of C I3P V , 24 7
for C BPV , 39 of JWA , 190, 246
m ay- t es ting , 109 predecessor of a to ken , 177
wi th cell gene rat ion, 122 Predom, 84
wit h co ntro l, 100 pred om a in , 84, I l l , 289, 294
prefix-cl osed , 185, 187
wi th glo bal st or e, 92
premo noid a l cat egory, 329
wi th p rinting, 39
print , 8
for C BV, 17
prin t in g se mantics
for J WA , 155
for C B N, 22
OpBimod, 111
for C B P V , 39
opbimodu le , 110, 240
for C B V, 11
p ointwise id ea l, 110, 24 0
product , 4, 218
operation sy m bol, 251
categorical, 14, 265
opGr , 213
in CBPV j ud gement model, 228
opGrothend ieck construction, 213
in stagger ed Freyd cat egory, 33 1
O ppon en t-await in g play , 185, 187
K leisli , 237
O pponen t -move , see O- m ove
p at t ern- m a t ch , 5, 30 , 300, 30 1
project ion , 5, 30, 300, 301
P- bracket ed play, 20 1 wit h righ t m odu les , 22 7, 271
P-m ove, 182 , 185, 187 project ion , 4
paramet ricity, 137 provably equ ivalent se que nts, 158
paramet rized inva ria nt , 74 pseud o-com p ut at ion -type in CBV, 316
pa ra m etrized m inima l inva ri ant , 74 pseu d o-val ue-ty p e in C I3N, 321
para m et ri zed rep res en t abilit y, 242 , 273- pseudoref , 172, 173
277 , 280 Pt; EJ (aren a o peration) , 177
pa rtial term , 78 push , xxxiii, 33
pa rt.ia l-on -rninirnals, 84
P art min, 84 Q/ A- la b elled arena, 195
pattern-matc h, 4 , 45 Q/ A-resp ecti ng isomorphism , 196
pepo, 72 q ues ti on -m ove , 195
pending Q-m ove, 200
p lai n m ap , 24 read , 192
p lay read; , 192
awaiting Oppon en t , 185, 187 read in g, 91, 118
awaiti ng Player , 185, 187 read ; ,,, 192
in fini t e, 185 , 187 rea lizability, 66
no nreturning -command (de fa u lt) , 185 rec ursion, 66-76
value, 186 ty p e, 68- 76 , 295
Player-awaiti ng play, 185 , 187 ref iE! , 192
INDEX 351
r ef , 118 with printing, 22
ref A (ty pe of A-storing cells) , 118 for C B P V
ref e (type of C-cells), 123 poin t er ga mes , 195
re flect ion, full, 333 wit h cell generat ion , 131
re indexed mo r ph ism, 211 wit h cell generation + d ivergence ,
reindexi ng fun ct or , 211 134
relation m od el , 107- 109, 239 wit h cell generation + print in g,
repres entab le obj ect , 26 1 133
repres entation , 261 wit h cont ro l, 101
represent ing obj ect for fun ct or, 265 wit h cont rol + printing , 106
Res, 235 wit h er ra t ic choice, 108
reso lut ion of monad , 235 wit h errors , 114
res ult type of ope ration sy m b ol, 25 1 wit h glob al st or e , 92
r et urn as jump, xxx vi, 148, 195 wit h global sto re + print ing, 95
re t urne r, xx xiv , 29 wi th p rinting, 40
in C BV, 11 wi th recursion, 67
reversible derivation, 7, 60 , 218 for C B V
converte d into functor , 26 6, 268 wit h printing, 13
ri gh t adj uncti ve , 225, 266 for JWA
in staggered Freyd categor y, 331 poi nt er ga m es , 194
ri gh t ex p one nt ia l-adj unct ive , 245, 266 with printing, 154
in stagge red Fr eyd category, 332 source ar ena, 186
right ex p one nt ial-p ro d uct- adj unct ive, 245, source m ove, 186
266
source obj ect, 33 0
in st agge re d Fr eyd category, 332
sour ce-to-target fun ction , 330
rig ht module , 208
stack, xxx iii, 32, 33, 96
locall y indexed , 215
em pty, 33
ri gh t p rodu ct -adjuncti ve , 245 , 247, 266
st ac k- passing-sty le, see St kPS
in staggere d Fr ey d catego ry, 332
stac kfree-in-stac k a re na , 199, 248
root of an are na, 177
stac kfre e-in -value arena, 199, 248
ro ot re p rese nt s d ata , 176
st a cks
root , 177
categorical semantics, 221
rt , 176
conti nu ation se mant ics , 104
sa fe retu rner , 310 equational theory, 58
Scott sem a nt ics , 40 , 65-86 erratic choice sem a nt ics, 109
for C BN , 23 error semanti cs for , 114
for C B V, 13 global store se mant ics, 93
Scott-E rshov, see d omain p ossibl e world se m a ntics, 129
Scott-Ers ho v/ Abramsky-M cCusker, see print in g sem a ntics , 41
predomain stagg er ed catego ry, 330
SE CD machine , 32 stagg er ed Fr eyd category, 330
selector of a jump, 176 stk, 96 , 98
self , 212 StkPS transform , 141, 148, 194 , 238
self eN, 271 is a n eq uivalence , 160-168
semantics of types StkPS tran sforms , other, see CPS
x -calculus , 250 store, xxxiii, 117
se p arate n aturality, 262 gene ral, see cell generati on
seq ue nce d com p utat ion, xxxiv glob al, see globa l store
sequent, 251 , 255 , 259, 332 st rategy
SFL, xxxi nonreturn ing co m mand (d efaul t),
SFP L, xxxi 185
Sig, 251 , 255 va lue, 187
sign atu re, 251 , 25 5, 259, 332 strengt h of m onad , 15
simple fib ration , 212 strict con ti nuo us fu nction , 41
sing le-t h read ed , 186 strong a dj unction , 234
sou nd ness w.r. t. operationa l semantics strong monad, see m on ad , st rong, 17, 216
for C BN struct ur e
352 CA LL-B Y-P USH- VALUE

of A -set , 21, 129 from FG-C BV to C BP V, 314-319


of algebra, 24 fro m lazy to FG-CBV, 313-3 14
sub-arena, 177, 196 trivia l model, 63 , 236
sub-arena-family, 179 trivialization t ra ns for m , 236
sub-bilimit- compact,84 t u ple types in jumbo >.-ca lculus, 300-30 1
subject red ucti on ty pe ca nonica l form
for C-machine, 152 for C BP V , 61, 199
for CK- machin e, 35 for JWA, 156 , 157, 179
substitution into stack, 36 type-r epresent, 177, 178
substitution lem m a, 217 , 220
su bs um pt ive trans lation, xxx , xxx ii Us, 138
successor of a to ken, 177 under, 177
su m type, 4, 25 unfold , 69
Sw (stores in world w) , 125 un it of adj u nction, 235
un iver sa l a re na, 174
T ty pe in CBV , 305 un iver sa l element, 26 1
T , mo nad on MGraph T' 252, 255 un iversal mod el, 169
tag, xxx vi un ty ped >.-ca lcul us, 20
t ar get a re na, 186
target m ove, 186 ' p ,271
target objec t , 330 vY, 271
teache r, 145 va l-ob je ct , 222 , 254, 330
hom om orphism, 148 val ue, xxxiv, 90
te rminal te rm, 8 in CBV , 10, 11
in C BN, 18 in JWA, 143
t ermination va lue gam e, 186
for C B N, 18 value play, 186
for C BPV, 30 valu e strategy, 187
for C BP V + control, 100 value type , xxxvi
for CB V , 10 variable, xxxi i
for J WA , 153 vert ex , 14
wit hout t hu n k storage, 123 of cocon e, 70
te rms b uilt fro m signatur e, 252 of rep resenting obj ect , 265, 267
th eory, 335 visibility cond it ion, 171
thread -poi nt er, 191, 193 vStrat, 187
thu nk , xxx iv, 103
t hunk storag e, 137- 140 W ,117
t hun k sto rage d isa llowed , 123 w-com p utat ion, 120
tok , 176 w-store , 120
to ken, 174 w-value, 120
to tal t erm , 78 weakenin g , xxxi ii, 98
trace jumpabout , 145 where (stack for mation) , 58
trans la tio n "here (st a ck format ion), 161
fro m CBN t o CBP V , 45 , 319-325 world , 117 , 119
from CBP V +cont ro l t o JWA , see world-st or e, 117, 120
Stkl'S t ransfor m write . , 192
from C BV t o CBPV, 42 written. , 192
from CG -C BV to F G- CBV, 308-3 10 written ; ,r , 192

You might also like