没有合适的资源?快使用搜索试试~ 我知道了~
首页implementing functional languages
implementing functional languages
需积分: 10 48 浏览量
更新于2023-05-22
评论
收藏 1.24MB PDF 举报
实现函数式编程语言,可以帮助你写一个语法分析器,书中主要使用haskell
资源详情
资源评论
资源推荐

Implementing Funtional Languages:
a tutorial
Simon L Peyton Jones
Department of Computing Siene, University of Glasgow
and David R Lester
Department of Computer Siene, University of Manhester
1991
Marh 23, 2000

This b o ok is dediated to the memory of our friend and olleague Jon Salkild
(1963-1991).
1

Contents
Prefae 5
1 The Core language 10
1.1 An overview of the Core language . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2 Syntax of the Core language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.3 Data types for the Core language . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.4 A small standard prelude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.5 A pretty-printer for the Core language . . . . . . . . . . . . . . . . . . . . . . . . 20
1.6 A parser for the Core language . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2 Template instantiation 42
2.1 A review of template instantiation . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.2 State transition systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
2.3 Mark 1: A minimal template instantiation graph reduer . . . . . . . . . . . . . . 50
2.4 Mark 2:
let(re)
expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.5 Mark 3: Adding up dating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2.6 Mark 4: Adding arithmeti . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.7 Mark 5: Strutured data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
2.8 Alternative implementations
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
2.9 Garbage olletion
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3 The G-mahine 83
3.1 Intro dution to the G-mahine . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
3.2 Co de sequenes for building templates . . . . . . . . . . . . . . . . . . . . . . . . 85
3.3 Mark 1: A minimal G-mahine . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
2

3.4 Mark 2: Making it lazy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
3.5 Mark 3:
let(re)
expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
3.6 Mark 4: Adding primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
3.7 Mark 5: Towards b etter handling of arithmeti . . . . . . . . . . . . . . . . . . . 119
3.8 Mark 6: Adding data strutures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
3.9 Mark 7: Further improvements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
3.10 Conlusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
4 TIM: the three instrution mahine 143
4.1 Bakground: How TIM works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
4.2 Mark 1: A minimal TIM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
4.3 Mark 2: Adding arithmeti . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
4.4 Mark 3:
let(re)
expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
4.5 Mark 4: Updating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
4.6 Mark 5: Strutured data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
4.7 Mark 6: Constant appliative forms and the o de store
y
. . . . . . . . . . . . . . 189
4.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
5 A Parallel G-mahine 196
5.1 Intro dution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
5.2 Mark 1: A minimal parallel G-mahine . . . . . . . . . . . . . . . . . . . . . . . . 200
5.3 Mark 2: The evaluate-and-die mo del . . . . . . . . . . . . . . . . . . . . . . . . . 209
5.4 Mark 3: A realisti parallel G-mahine . . . . . . . . . . . . . . . . . . . . . . . . 212
5.5 Mark 4: A b etter way to handle blo king . . . . . . . . . . . . . . . . . . . . . . 214
5.6 Conlusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
6 Lamb da Lifting 217
6.1 Intro dution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
6.2 Improving the
expr
data typ e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
6.3 Mark 1: A simple lambda lifter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
6.4 Mark 2: Improving the simple lamb da lifter . . . . . . . . . . . . . . . . . . . . . 230
6.5 Mark 3: Johnsson-style lambda lifting . . . . . . . . . . . . . . . . . . . . . . . . 231
6.6 Mark 4: A separate full laziness pass . . . . . . . . . . . . . . . . . . . . . . . . . 236
3

6.7 Mark 5: Improvements to full laziness . . . . . . . . . . . . . . . . . . . . . . . . 250
6.8 Mark 6: Dependeny analysis
y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
6.9 Conlusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
A Utilities mo dule 262
A.1 The heap type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
A.2 The asso iation list typ e . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
A.3 Generating unique names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
A.4 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
A.5 Other useful funtion denitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
B Example Core-language programs 268
B.1 Basi programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
B.2
let
and
letre
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
B.3 Arithmeti . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
B.4 Data strutures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
4
剩余295页未读,继续阅读
















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0