├── .gitignore
├── README.md
├── SUMMARY.md
├── book.json
├── custom
├── css
│ └── app.css
└── js
│ └── app.js
├── package.json
├── section1
├── README.md
├── big-step-eval.scm
├── chapter-5-exercises.txt
└── small-step-eval.rs
├── section2
└── README.md
├── section3
└── README.md
├── section4
└── README.md
├── section5
└── README.md
├── section6
└── README.md
└── section7
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | _book/
2 | node_modules/
3 | .swp
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # StudyGroup-TaPL
2 |
3 | A Types and Programming Languages Study Group.
4 |
5 | 供大家打打寫寫的 Hackpad:
6 | https://hackpad.com/TaPL--y8iYXwtcG1G
7 |
8 | 第三次報名表:
9 | http://tapl.kktix.cc/events/d79d3108-280938-937683
10 |
11 | ## 日程表
12 |
13 | | 日期 | 地點 | 預定進度 | 實際進度 |
14 | |------------|------|---------------------|-------------------------------------------|
15 | | 2015-11-28 | 彩色巴黎 | 未指定 | OCaml入門、環境設定
TAPL前置知識要求
簡略討論 Chapter 4 所設定的語言 (7 rules) |
16 | | 2015-12-19 | 火腿書房 | 第七章 (英文版第 89 頁止) | |
17 | | 2016-01-30 (預定) | 火腿書房(預定) | Part 2 Simple Types 結束 (英文版第 178 頁止) | |
18 |
19 | ## 實作
20 |
21 | 歡迎大家把實作品的網址貼在這邊分享
22 |
23 | | 參加者 | 網址 |
24 | |-------------|-------------------------------------|
25 | | drm343 | https://github.com/drm343/TaPL-implement |
26 |
--------------------------------------------------------------------------------
/SUMMARY.md:
--------------------------------------------------------------------------------
1 | # 目錄
2 |
3 | * [1 Introduction](section1/README.md)
4 | * [2 Mathematical Preliminaries](section2/README.md)
5 | * I Untyped Systems
6 | * [3 Untyped Arithmetic Expressions](section3/README.md)
7 | * [4 An ML Implementation of Arithmetic Expressions](section4/README.md)
8 | * [5 The Untyped Lambda-Calculus](section5/README.md)
9 | * [6 Nameless Representation of Terms](section6/README.md)
10 | * [7 An ML Implementation of the Lambda-Calculus](section7/README.md)
11 |
--------------------------------------------------------------------------------
/book.json:
--------------------------------------------------------------------------------
1 | {
2 | "plugins": [
3 | "customtheme",
4 | "include-highlight"
5 | ],
6 | "pluginsConfig": {
7 | "customtheme": {
8 | "css": ["custom/css/app.css"],
9 | "js": ["custom/js/app.js"]
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/custom/css/app.css:
--------------------------------------------------------------------------------
1 | /* hide chapter numbers */
2 | .chapter > * > b {
3 | display: none;
4 | }
5 |
--------------------------------------------------------------------------------
/custom/js/app.js:
--------------------------------------------------------------------------------
1 | /* this is a placeholder */
2 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "studygroup-tapl",
3 | "version": "0.0.1",
4 | "description": "A Types and Programming Languages Study Group.",
5 | "main": "index.html",
6 | "dependencies": {
7 | "gitbook-plugin-customtheme": "git://github.com/caasi/gitbook-plugin-customtheme.git",
8 | "gitbook-plugin-include-highlight": "^0.1.0"
9 | },
10 | "devDependencies": {},
11 | "scripts": {
12 | "test": "echo \"Error: no test specified\" && exit 1"
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "git+https://github.com/cschat-tw/StudyGroup-TAPL.git"
17 | },
18 | "author": "drm343",
19 | "license": "ISC",
20 | "bugs": {
21 | "url": "https://github.com/cschat-tw/StudyGroup-TAPL/issues"
22 | },
23 | "homepage": "https://github.com/cschat-tw/StudyGroup-TAPL#readme"
24 | }
25 |
--------------------------------------------------------------------------------
/section1/README.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | * [Semantics of System F](http://www.paultaylor.eu/stable/semsf.pdf)
4 |
5 | Related Reading 中提到,有關 System F 的介紹。
6 |
7 | * [A Formulation of the Simple Theory of Types](https://www.classes.cs.uchicago.edu/archive/2007/spring/32001-1/papers/church-1940.pdf)
8 |
9 | Alonzo Church 在 1940 年發表,有關 Types Therory 的論文。
10 |
11 | ## Example Code
12 |
13 | 書上範例只是一部份的程式碼,完整的程式碼請從下列網址取得。
14 |
15 | * [Untyped System](http://www.cis.upenn.edu/~bcpierce/tapl/checkers/untyped.tar.gz)
16 |
17 | Untyped System 的 example code。
18 |
19 | * [tapl-Haskell](https://code.google.com/p/tapl-haskell/downloads/detail?name=tapl-haskell-0.1.tar.gz&can=2&q=)
20 |
21 | 用 haskell 實作的 tapl。
22 |
23 | ## Practices
24 |
25 | @b4283 的 `small-step-eval.rs` :
26 |
27 | !CODEFILE "./small-step-eval.rs"
28 |
29 | 與 `big-step-eval.scm` :
30 |
31 | !CODEFILE "./big-step-eval.scm"
32 |
--------------------------------------------------------------------------------
/section1/big-step-eval.scm:
--------------------------------------------------------------------------------
1 | ;; Interpreter: GNU Guile 2.0.11
2 | ;; 我無法確定這個實作完全遵守一樣的邏輯!
3 |
4 | ;; *更新*: 想了一想,cons 一個 'end 在 term 前面像是亂來的做法因為這樣把
5 | ;; type 的定義變得混雜了,或許使用和書裡面類似的定義才是正確的做法……
6 | ;; (即是所有 term 的 ctor 都有一個 `info' 參數,可以用來記憶 term 是否
7 | ;; 已經 eval 過)
8 |
9 | (use-modules (ice-9 match)
10 | (rnrs base)
11 | (ice-9 format))
12 |
13 | (define (is-numeric-val? t)
14 | (match t
15 | (('tm-zero) '(tm-true))
16 | (('tm-succ _) '(tm-true))
17 | (_ '(tm-false))))
18 |
19 | (define (eval* t)
20 | (match t
21 | (('tm-if ('tm-true) t2 t3) (eval* t2))
22 | (('tm-if ('tm-false) t2 t3) (eval* t3))
23 | (('tm-if t1 t2 t3)
24 | (let ((t1' (eval* t1)))
25 | (if (eq? (car t1') 'end)
26 | (cons 'end t)
27 | (eval* `(tm-if ,t1' ,t2 ,t3)))))
28 | (('tm-succ t1)
29 | (let ((t1' (eval* t1)))
30 | (if (eq? (car t1') 'end)
31 | (cons 'end t)
32 | (eval* `(tm-succ ,t1')))))
33 | (('tm-pred ('tm-zero)) '(tm-zero))
34 | (('tm-pred ('tm-succ t1))
35 | (let ((t1' (eval* t1)))
36 | (let ((t1'' (if (eq? (car t1') 'end) (cdr t1') t1')))
37 | (match (is-numeric-val? t1'')
38 | (('tm-true) t1'')
39 | (('tm-false) `(end ,t))))))
40 | (('tm-pred t1)
41 | (let ((t1' (eval* t1)))
42 | (if (eq? (car t1') 'end)
43 | (cons 'end t)
44 | (eval* `(tm-pred ,t1')))))
45 | (('tm-is-zero ('tm-zero)) '(tm-true))
46 | (('tm-is-zero ('tm-succ t1))
47 | (let ((t1' (eval* t1)))
48 | (let ((t1'' (if (eq? (car t1') 'end) (cdr t1') t1')))
49 | (match (is-numeric-val? t1')
50 | (('tm-true) '(tm-false))
51 | (('tm-false) (cons 'end t))))))
52 | (('tm-is-zero t1)
53 | (let ((t1' (eval* t1)))
54 | (if (eq? (car t1') 'end)
55 | (cons 'end t)
56 | (eval* `(tm-is-zero ,t1')))))
57 | (_ (cons 'end t))))
58 |
59 | (define (eval t)
60 | (let ((t' (eval* t)))
61 | (match t'
62 | (('end t1 ...) t1)
63 | (_ t'))))
64 |
65 | (define (eval-print t)
66 | (format #t "~a => ~a\n" t (eval t)))
67 |
68 | (eval-print '(tm-is-zero (tm-zero)))
69 | (eval-print '(tm-is-zero (tm-pred (tm-pred (tm-succ (tm-zero))))))
70 | (eval-print '(tm-pred (tm-zero)))
71 |
72 | (eval-print '(tm-pred (tm-succ
73 | (tm-pred (tm-succ
74 | (tm-pred (tm-succ (tm-zero))))))))
75 |
76 | (eval-print '(tm-if (tm-true)
77 | (tm-is-zero (tm-succ (tm-true)))
78 | (tm-false)))
79 |
80 | (eval-print '(tm-if (tm-false)
81 | (tm-zero)
82 | (tm-pred (tm-succ (tm-zero)))))
83 |
--------------------------------------------------------------------------------
/section1/chapter-5-exercises.txt:
--------------------------------------------------------------------------------
1 | 5.2.1
2 | or = La. Lb. a tru b
3 | not = La. a fls tru
4 |
5 | 5.2.2
6 | succ = Ln. Ls. Lz. n s (s z)
7 |
8 | 5.2.4
9 | expt = Lm. Ln. m (times n) C0
10 | ;; not sure about this one
11 |
12 | 5.2.5
13 | sub = Lm. Ln. n prd m
14 |
15 | 5.2.7
16 | equal = Lm. Ln. iszro (sub m n)
17 |
--------------------------------------------------------------------------------
/section1/small-step-eval.rs:
--------------------------------------------------------------------------------
1 | // eval1() is pretty much okay until eval() came along,
2 | // borrow checker stopped me from finishing it.
3 | #![feature(box_syntax, box_patterns)]
4 |
5 | #[derive(Debug)]
6 | enum Term {
7 | True,
8 | False,
9 | If(Box, Box, Box),
10 | Zero,
11 | Succ(Box),
12 | Pred(Box),
13 | IsZero(Box)
14 | }
15 |
16 | fn eval1(t: Term) -> Term {
17 | match t {
18 | Term::True => Term::True,
19 | Term::False => Term::False,
20 | Term::If(box a, box b, box c) =>
21 | match a {
22 | Term::True => eval1(b),
23 | Term::False => eval1(c),
24 | _ => Term::If(box eval1(a), box b, box c)
25 | },
26 | Term::Zero => Term::Zero,
27 | Term::Pred(box Term::Succ(box n)) => n,
28 | Term::IsZero(box Term::Zero) => Term::True,
29 | Term::IsZero(_) => Term::False,
30 | _ => Term::False
31 | }
32 | }
33 |
34 | fn main() {
35 | println!("{:?}", eval1(Term::If(
36 | box Term::True,
37 | box Term::Pred(box Term::Succ(box Term::Zero)),
38 | box Term::False))
39 | );
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/section2/README.md:
--------------------------------------------------------------------------------
1 | # Mathematical Preliminaries
2 |
3 | This is a placeholder.
4 |
--------------------------------------------------------------------------------
/section3/README.md:
--------------------------------------------------------------------------------
1 | # Untyped Arithmetic Expressions
2 |
3 | This is a placeholder.
4 |
--------------------------------------------------------------------------------
/section4/README.md:
--------------------------------------------------------------------------------
1 | # An ML Implementation of Arithmetic Expressions
2 |
3 | This is a placeholder.
4 |
--------------------------------------------------------------------------------
/section5/README.md:
--------------------------------------------------------------------------------
1 | # The Untyped Lambda-Calculus
2 |
3 | This is a placeholder.
4 |
--------------------------------------------------------------------------------
/section6/README.md:
--------------------------------------------------------------------------------
1 | # Nameless Representation of Terms
2 |
3 | This is a placeholder.
4 |
--------------------------------------------------------------------------------
/section7/README.md:
--------------------------------------------------------------------------------
1 | # An ML Implementation of the Lambda-Calculus
2 |
3 | This is a placeholder.
4 |
--------------------------------------------------------------------------------