types and programming languages pdf 2002

types and programming languages pdf 2002

h h y)(此处标 *),之所以说类似是因为它也有这种紧邻在一起的两个同样的项 (λx. The exercises range from easy to challenging and provide stimulating material for beginning and advanced readers, both programmers and the more theoretically minded." h h y))和将 (λy. •Pierce, B. C. (2002) Types and Programming Languages. %PDF-1.7 Each rule is read, “If we have established the statements in the premise(s) listed above the line, then we may derive the conclusion below the line.” The fact that T is the smallest set s... 第 8 章给一个包含自然数和 bool 的算术表达式系统引入了类型的概念和推导一个表达式的类型的 typing rules(例如“如果 t1 是 bool,t2 和 t3 类型同为某个类型 T,则 if t1 then t2 else t3 的类型为 T”),基于 typing rules 得到的项和类型之间的关系被抽象的叫做 typing relation。如果根据 typing rules 可以推导出某个项 t 属于某个类型 T(写作 t:T),那么 t 被称为 well typed 的。接下来根据这个系统里的 typing re... © 2005-2020 douban.com, all rights reserved 北京豆网科技有限公司, https://www.seas.harvard.edu/courses/cs152/2010sp/lectures/lec08.pdf, https://www.youtube.com/watch?v=YScIPA8RbVE. x x y)) (λx. The figure shows an example of machine code. PDF | On Oct 1, 2016, Usman Opeyemi Lateef and others published INTRODUCTION TO COMPUTER PROGRAMMING (BASIC) | Find, read and cite all the research you need on ResearchGate 最感谢的莫过于OPLSS 2018的pre-session,在上课的过程中不知不觉建立了对于各项type rules的直观理解,在其后再次回顾这本书各项内容都变得简单易懂。但有趣的是,虽然Computational Type Theory被Bob Harper称为最符合直觉的,在最后一周的讲座中基本没有听懂其内容。 The study of type systems--and of programming languages from a type-theoretic perspective -- -has important applications in software engineering, language design, high-performance compilers, and security.This text provides a comprehensive introduction both to type systems in computer science and to the basic theory of programming languages. 6.821 teaches the principles of functional, imperative, and logic programming languages. Several programming languages exist and new are being created always. f (λy. Therefore, material on compilation, type systems and memory management should directly confront their biases. 比较难理解的一本理论书。但稍有感悟之后,再看回头这些茫茫多的程序语言的设计思想还是别有一番滋味!, 13/5/2 pdf英文+实体中文对照 g (λy. The study of type systems for programming languages has emerged over the past decade as one of the most active areas of computer science research, with impor-tant applications in software engineering, programming language design, high-performance compiler implementation, and security of information networks.   1人喜欢. Visual Basic can also be used within other Microsoft software to program small routines. It focuses on pragmatics, with the right level of necessary theory. 最感谢的莫过于OPLSS 2018的pre-session,在上课的过程中不知不觉建立了对于各项type rules的直观理解,在其后再次回顾这本书各项内容都变得简单易懂。但有趣的是,虽然Computational Type Theory被Bob Harper称为最符合直觉的,在最后一周的讲座中基本没有听懂其内容。 Dependencies between chapters are explicitly identified, allowing readers to choose a variety of paths through the material.The core topics include the untyped lambda-calculus, simple type systems, type reconstruction, universal and existential polymorphism, subtyping, bounded quantification, recursive types, kinds, and type operators. Advanced Topics in Types and Programming Languages … %���� Title. : alk. Request PDF | On Jan 1, 2006, Mats Kindahl published Review of "Types and Programming Languages by Benjamin C. Pierce", MIT Press, 2002. for any element n ∈S with n ≤ s and n ≤ t, we have n ≤m. Since types and programming languages are by now a large subject, a stringent selection of topics is necessary. Subsequent chapters will show you how to use different data types in different situations. 1篇, 2020-05-02 11:24 Overview Birds-eye view of what’s happening in the world of types for programming languages (not logic or theorem proving) Using 1993 and 2003 as reference points 2/89. A, we proceed by proving, by induction on types, that all terms of type A possess property P, all terms of type A→A preserve property P, all terms of type (A→A)→(A→A) preserve the property of preserving property P, and so on. • Hand-held programming devices are sometimes used to program small PLCs • They are compact, inexpensive, and easy to use, but are not able to display as much logic on screen as a computer monitor. Advanced Topics in Types and Programming Languages … 右边的部分),用它替换掉加数的 z;乘法是设置乘数之一的 z 为 0,s 为加另一个乘数;减一操作类似于链表中的双指针法。, 证明了纯 lambda 演算可以表达自然数、bool 和条件语句之后,接下来作者为了方便就引入了正常的自然数、bool 和 if 语句。, 然后讲了怎么通过使用 fix 组合子在 lambda 演算里使用递归,fix 组合子是:, fix = λf. A type system is a syntactic method for automatically checking the absence of certain erroneous behaviors by classifying program phrases according to the kinds of values they compute. sion of some programming languages, specifically Lua and Objective-C, has been removed. Ada was one of the first widely-used languages to have a language construct representing an abstraction (a package), an abstract data type (a private type), multi-threading (tasks), generic templates, exception handling, strongly-typed separate compilation, subprogram inlining, etc. Computer programming languages are used to to communicate instructions to a computer. x x y)), 这是一个神奇的构造,它里面有两个紧邻的相同的项 (λx. A type system is a syntactic method for automatically checking the absence of certain erroneous behaviors by classifying program phrases according to the kinds of values they compute. They are often misled on topics such as efficiency and correctness. 起初是没有太明白书中的内容的。即使是拥有Haskell的基础,在研读时仍有各种疑惑,对于证明习题也是充满了恐惧和不知如何开始。 (展开), > Although this book is designed around a one semester introductory course, it should also be suitable for self-study students and for people with substantial programming experience but without similar computer science knowledge. h h y) 仍可以在将 g 展开之后进行归约,精妙之处在于:g 是传入给 fix 的参数,是使用 fix 组合子的程序员来控制的,在 g 里程序员可以把 g 的参数,也就是 (λy. 拗口, 没有索引, 生僻的单词翻译的时候没有附上原英文单词. Contents Preface xiii 1 Introduction 1 1.1 Types in Computer Science 1 1.2 What Type Systems Are Good For 4 1.3 Type Systems and Language … Comparative Studies of 10 Programming Languages within 10 Diverse Criteria -- a Team 10 COMP6411-S10 Term Report 4 1.9 PHP Language Overview PHP is a powerful scripting language that can be run by itself in the command line of any computer with PHP installed [156]. of type systems--and of programming languages from a type-theoretic perspective -- -has important applications in software engineering, language design, high-performance compilers, and security.This text provides a comprehensive introduction both to type systems in computer science and to the basic theory of programming languages. Programming languages (Electronic computers). Material on the newer language, Swift, was added to several chapters. <> stream A language feature is defined by its statics, the rules govern-ing the use of the feature in a program, and its dynamics, the rules defining how programs using this feature are to be executed. In this work we examine six programming languages … Machine code, one example of a low-level language, uses code that consists of just two numbers — 0 and 1. Programming languages are used for controlling the behavior of computer machines. 最感谢的莫过于OPLSS 2018的pre-session,在上课的过程中不知不觉建立了对于各项type rules的直观理解,在其后再次回顾这本书各项内容都变得简单易懂。但有趣的是,虽然Computational Type Theory被Bob Harper称为最符合直... 起初是没有太明白书中的内容的。即使是拥有Haskell的基础,在研读时仍有各种疑惑,对于证明习题也是充满了恐惧和不知如何开始。 1 : fnt (n-1) + fnt (n-2)), 2020-05-20 22:26 x x y)),注意到给 fix 传一个参数 g 之后,它变成了, 这个表达式可以做 beta-reduction,设 (λx. The study of type systems--and of programming languages from a type-theoretic perspective -- -has important applications in software engineering, language design, high-performance compilers, and s... A type system is a syntactic method for automatically checking the absence of certain erroneous behaviors by classifying program phrases according to the kinds of values they compute. 在数学中,类 X 上的一个二元关系 R 被称为是良基的,当且仅当所有 X 的非空子集都有一个 R-极小元, 2019-06-18 11:01 x x y))。将上面的两步归约总结一下,也就是 fix g = h h = g (λy. The concrete types of some programming languages, such as integers and strings, depend on practical issues of computer architecture, compiler implementation, and language design. A comprehensive introduction to type systems and programming languages. •Pierce, B. C. (ed) (2005) Advanced Topics in Types and Programming Languages. 可惜翻译的很差. (, 喜欢读"Types and Programming Languages"的人也喜欢的电子书, 喜欢读"Types and Programming Languages"的人也喜欢. "Types and Programming Languages is carefully written with a well-balanced choice of topics.   2人喜欢, 第 13 章讲如何在现有的系统中加入 reference,reference 可以理解为一个储存着某个值的 cell,cell 里储存的值可以被读出来,也可以被修改,所以读取同一个 cell 两次可能得到不同的值。每一个在常见语言里,每一个变量都有这样的性质,从本书的视角,这些语言里的每一个变量都是一个 reference。, 两个 reference 可以指向同一个变量(这个行为像 python 的对象和 C++ 里的指针/引用),这叫做 aliasing,这给分析程序的行为带来了一些麻烦,例如语句 s := 42; s:= !r(其中 := 是给 reference 所指向的变量赋值,!r 是对 reference r 解引用),在大部分情况下可以直接被理解为 s := !r,但如果 s 和 r 指向同一个变量,那情况就完全不一样了。然而两个 reference 可以指向同一个变量的特性也正是它的有用之处,许多现象都可以用这个特性来方便的描述(不举例了 QAQ)。, reference 一个有趣的应用是用 reference 实现可读可写的数组(像 C 语言里的数组那样),一个自然数数组类型 NatArray,可以用函数类型 (Nat -> Nat) 的引用来实现,相当于一个可变的 Nat->Nat 的映射。更新这个数组的元素就通过修改这个映射来实现。, 此外,每一个新的 reference 都会产生一个可变的变量,考虑到 reference 的 aliasing,我们不能像对待普通变量一样在 reference 的作用域结束时就简单释放它所对应的变量所占的空间,因为这部分空间可能仍被另一个 reference 所使用,那么如何判断一段空间是否可以释放就成为了一个问题,这就是很多常见语言里的垃圾回收的概念 QAQ, 接下来本书讨论了怎样用严谨的语言来描述 reference,特别是把它纳入到已有的 evaluation rules 和 typing rules 的体系内,并且仍保持 type safety。首先,一个新的 term:ref t,被加入进来,如果 t 的类型是 T,那 ref t 的类型就定义为 Ref T。, 在涉及到 reference 的 evaluation rules 里,需要有一个数据结构来存储每一个 reference 指向的变量的值,它就像求值时的“环境”,解引用操作就是从这个环境里取值,赋值操作就是更新这个环境,所以这些 evalution rules 都加入了一个新的元素 stores 表示这个环境。此外,已有的、不涉及 reference 的 evaluation rules 里也要加入这个环境,它们需要把这个环境从 premise 继承到 conclusion。, 接下来,每个 Ref T 类型的项都应该对应一个指向某个 T 类型变量的 cell。因为在编译时没有办法知道有多少个、什么样的 cell 会被创建,所以 cell 只能在运行时被创建,如果 ref t 可以被归约,那在归约 ref t 的同时,创建一个包含 t 的 cell 是一个很合理的选择(相当于 C++ 和 Java 的构造函数,它们在被执行时创建一个对象)。顺着这个思路,ref t 归约得到的项 (叫做 l,小写的 L)应该和这个新创建的 cell 有一种对应关系,以使我们能够通过 l 来操作这个 cell 里的内容。在常见语言里,l 其实就是这个 cell 的内存地址,但我们没有必要被这些涉及到硬件的实现细节所干扰,我们可以认为这个 l 就是一个黑盒子,我们只需要知道通过 l 可以访问这个 cell 就可以了,我们把它们称作 store location。, store location 只会作为对含 ref t 的表达式做 evaluation 的结果而产生,不会直接出现在程序员所写的代码里,如果为了做静态类型检查,我们没有必要去考虑 store location 的类型,但我们如果想证明这个类型系统的 safety,即 progress(每个有类型的项都是 value 或者可以归约)和 preserve(归约产生的新项仍然保持类型不变),那 store location 作为 ref t 归约产生的新项,一定要有一个类型才行。, 到目前为止,已有的 typing rules 都形如 “若 t1 属于 A->B 类型,t2 属于 A 类型,则 t1 t2 属于 B 类型”,不涉及到 t1、t2 是由什么归约而来的。然而对于光秃秃的黑盒子 store locations,我们没办法按照上面的形式去静态的判断出它们的类型(另一方面,其实它们的类型非常容易想象出来:按照 preserve 的要求,如果某个 store location 是通过类型为 Ref T 的项归约产生的,那它的类型也应该是 Ref T)。所以我们只有新增一个数据结构叫做 store typing,保存每一个 store location 都是由什么类型的项归约而来,在类型推导时去查这个数据结构,才能知道某个 store location 的类型。这把类型推导和表达式的归约混在了一起,不过好在这只涉及到对 safety 的证明,在对程序员所写的程序做静态类型检查时,因为不会出现 store location,所以不需要先运行程序才能做类型检查。, 接下来是对 safety 的证明,这个没有太多花样,我们其实是为了保证 preserve 才用新增 store typing 的方法来改造 typing rules、给 store locations 赋予类型,所以 preserve 肯定是满足的,而新增 reference 对 progress 这个性质也没有什么重要的影响。, 然后是第 14 章,第 14 章讲了如何引入异常(exceptions),程序抛出异常时,这个异常会沿着调用栈向上传播直到到达最顶层接着使程序终止,或是遇到某个 error handler。书中添加了一个新的 term 叫做 error,并规定它只是 term 而不是 value,添加了两个 evaluation rules:error t2 -> error 和 v1 error -> error,这两个 rules 使得 error 可以沿着调用栈无条件的向上传播。此外,因为 error 只是 term 而不是 value,所以形如 (lambda x: 0) error 的表达式只能按照 v1 error -> error 归约为 error 而不能按照函数调用的归约规则(这个规则要求参数必须为 value)归约为 0。以及,在 v1 error -> error 中,左边的项被要求一定是 value 而不是 term,是为了让形如 (fix (lambda x: x)) error 的表达式能够符合直觉地无限循环而不是归约为 error。, error 有一个特殊的 typing rule,它可以被认为是任何一个类型,这会破坏前几章提到的每个 term 最多只有一个类型的性质,但后续几章会讲到一些方法可以容纳这个特殊的 typing rule。, 为了引入最简单的 error handing(error 向上传播的过程中如果碰到 error handler 就不再继续向上传播),书中加入了新写法 try t1 with t2:如果 t1 被归约为 error,则表达式归约为 t2,如果 t1 被归约为某个 value v1,则表达式也被归约为 v1。显然这要求 t1 和 t2 是同一个类型。, 接着本书升级了这个 error handling 的功能:程序抛出的异常不仅仅可以是一个普普通通的 error,而是可以抛出任何一个 value,这样就可以将详细的错误信息传递给 error handler。为了做到这个改进,原先的 term error 被 raise t 所替代,其中 t 就是被抛出的错误信息,和 error 相关的 evaluation rules 和 typing rules 被 raise t 继承了下来。try t1 with t2 里的 t2 现在的类型为一个函数类型 Texn->T,其中 Texn 是一个 t1 中可能抛出的所有类型组成的 variant,在 ML 系语言中有 extensible variant type 作为方便的在这个情况下构建 variant 的语法糖。另一个语言 Java,用抛出不同类型(class)的对象起到这里 variant 的效果,每一个可能作为异常抛出的对象都是 Java 中的 Throwable 类的子类。这比 ML 的做法更强大一些,因为不同的 class 可以有继承关系,而 variant 中不同的 tag 则是平级的。还有一个重要的不同点是 Java 的 exceptions 是 checked exceptions,函数可能抛出哪些异常是函数签名的一部分,并且函数调用者必须处理函数可能抛出的异常。, (玩 telegram 的小伙伴可以关注 https://t.me/daquexiannotebook ~ 读书笔记是从上面搬运过来的,也有讨论群), 2020-05-02 11:03 One way to classify programming languages is either as low-level languages or high-level languages. In addition, a new section on optional types was added to Chapter 6 . 更多书评 Types and programming languages / Benjamin C. Pierce p. cm. In this way we establish a foundation for the study of programming languages. Advanced Topics in Types and Programming Languages builds on Benjamin Pierce's Types and Programming Languages (MIT Press, 2002); most of the chapters should be accessible to readers familiar with basic notations and techniques of operational semantics and type systems--the material covered in the first half of the earlier book. The course involves substantial programming assignments and problem sets as … :s������qk���A�uq$��8��]�1�u�E]�q�i�X������. A type system is a syntactic method for automatically checking the absence of certain erroneous behaviors by classifying program phrases according to the kinds of values they compute. High level languages:Procedural-Oriented language (3GL),Problem-Oriented language (4GL),Natural language … endobj 33 0 obj Definition [Terms, by inference rules]: The set of terms is defined by the following rules: 2019-06-17 18:55 0 : (n == 1 ? for many of the advanced features in other programming languages. Low-level languages interact directly with the computer processor or CPU, are capable of performing very basic commands, and are generally hard to read. z 是一次也没有应用,和自然数的 0 等价。当我们需要使用自然数的时候,要做的只是选择合适的 s 和 z,就可以做到和自然数能做到的同样的事情。例如判断一个数是不是 0,只需要把 z 设置为 true,s 设置为一个恒返回 false 的函数;此外,church 数的加法是先取出被加数的“右半部分”(λs. h h y) 应用在什么参数上(应用在什么参数上是由 g 来决定的)。这就做到了和递归一样的效果。, 那么怎样写出一个合适的 g 以用 fix g 实现递归的效果也就很明确了,首先 g 应该接受一个参数,这个参数和上述的 (λy. n == 0 ? x x y)) y) = g (λy. A programming language is a formal language comprising a set of instructions that produce various kinds of output.Programming languages are used in computer programming to implement algorithms.. h h y) 自由处理,可以将它丢弃,也可以将它应用在某个参数上。如果将它应用在某个参数 n 上,就有 (λy. Formally, type theory studies type systems. For example, C and Java programming languages use int to specify integer data, whereas char specifies a character data type. g (λy. 但也正是通过在OPLSS和其他在读PhD的交流中,意识到了安定的研究生活其实不为我所想要,CS这一学科也至多只是个人的爱好而已。虽然现在依然未明确生活目标,但CS终将也只是达成目标的过程而不是最终的结果吧。接下来一年的学习方向会转向经济和程序分析。. PHP was originally created by Rasmus Lerdorf in 1995 and stood for "Personal Home Page" and was released as a free, … Each chapter is accompanied by numerous exercises and solutions, as well as a running implementation, available via the Web. There are two types of programming languages, which can be categorized into the following ways: 1.Low level language: Machine language (1GL), Assembly language (2GL) 2. Different programming languages use different keywords to specify different data types. QA76.7 .P54 2002 005.13—dc21 2001044428. These programming languages become popular with use to different programmers because there is always a tradeoff between ease of learning and use, efficiency and power of expression. (λx. such as languages, complexity analysis, objects, and computability. •Pierce, B. C. (2002) Types and Programming Languages.   1人喜欢, 第 8 章给一个包含自然数和 bool 的算术表达式系统引入了类型的概念和推导一个表达式的类型的 typing rules(例如“如果 t1 是 bool,t2 和 t3 类型同为某个类型 T,则 if t1 then t2 else t3 的类型为 T”),基于 typing rules 得到的项和类型之间的关系被抽象的叫做 typing relation。如果根据 typing rules 可以推导出某个项 t 属于某个类型 T(写作 t:T),那么 t 被称为 well typed 的。接下来根据这个系统里的 typing relation,又能得出关于这个系统的下面这些结论:, 1. x x y)) (λx. Assembly language, anothe… λz. h h y)(和上面标 * 的式子一模一样),这就有了一种循环(字面意义的),每次循环都会应用一次 g,而程序员可以在 g 中控制是否终止循环(即丢弃 g 的参数 (λy. The study of type systems--and of programming languages from a type-theoretic perspective -- -has important applications in software engineering, language design, high-performance compilers, and security.This text provides a comprehensive introduction both to type systems in computer science and to the basic theory of programming languages. There are many excellent textbooks onProgramming languages, such as: I Programming Language Pragmatics, by Michael L. Scott I Practical Foundations of Programming Languages, by Robert Harper I Programming Languages, Principles and Paradigms, by Allen Tucker and Robert Noonan I... We will focus ontypesbecause I most language features can be discussed in the … 但也正是通过在OPLSS和其他在读PhD的交流中,意识到了安定的研究生活其实不为我所想要,CS这一学科也至多只是个人的爱好而已。虽然现在依然未明确生活目标,但CS终将也只是达成目标的过程而不是最终的结果吧。接下来一年的学习方向会转向经济和程序分析。 The approach is pragmatic and operational; each new concept is motivated by programming examples and the more theoretical sections are driven by the needs of implementations. We do this by defining a family of predicates, indexed by types. f (λy. 起初是没有太明白书中的内容的。即使是拥有Haskell的基础,在研读时仍有各种疑惑,对于证明习题也是充满了恐惧和不知如何开始。 paper) 1. ISBN 0-262-16209-1 (hc. 如果一个 term 属于类型 ...,那么这个类型一定是 ...,它的子 term 的类型一定是 ...。这称为 inversion lemma,第 10 章里用它来做类型检查。, 2. | Find, read and cite all … s (s z) 是 s 被应用在 z 上 2 次,和自然数的 2 等价,λs. A comprehensive introduction to type systems and programming languages. x x y)) 为 h,此时上式就是 h h,第一个 h 是函数,第二个 h 是参数,相当于把自己当作参数传给了自己,并且归约得到的也是一个类似的结构:, g (λy. Includes bibliographical references and index.   1人喜欢, 这次是第 15 章 subtyping,它是一个基础性的改动,并影响到已经添加的各个特性,这个功能的出发点是解决过于生硬的 type checking 规则,例如,某个函数接受一个 record 类型的参数,作用是把其中名为 x、类型为 Nat 的 field 返回出来,很显然它的参数可以是任意一个存在一个名为 x、类型为 Nat 的 field 的 record 类型,这一点是目前我们的系统描述不了的。为了解决这个问题,就引入了 subtyping 的概念:如果某个项 t 为 S 类型,并且 S 是 T 的子类型,那么这个项 t 也属于 T 类型。引入这个概念之后,只要为各种 record 类型定义适当的子类型关系,就可以解决这个问题。, 具体的说,对于 record 类型来说,在某个 record 类型上额外加上新的 field,或把某个 field 的类型变为它的某种子类型,或将 field 的顺序重新排列,得到的新类型都是原类型的子类型,例如 {x: Nat, y: {x: Nat, y: Nat}, z: Nat} 是 {y: {x: Nat}, x: Nat} 的子类型。此外,对于函数类型 (arrow 类型),如果 S1->S2 是 T1->T2 的子类型,则要求 S1 是 T1 的基类型(S1 和 T1 的子类型关系与 S1->S1 和 T1->T2 的子类型关系相反,这称为逆变),S2 是 T2 的子类型(这和逆变相反,称为协变)。这个子类型关系背后的逻辑是,我们希望在所有需要 T1->T2 的地方可以以 S1->S2 来替代,既然 T1->T2 接受类型为 T1 的参数,那替代它的 S1->S2 一定也要至少能够接受类型为 T1 的参数,这要求 S1 是 T1 的基类型,另一方面,T1->T2 返回 T2,为了让 S1->S2 的返回值也能够在所有需要 T2 的地方正常使用,S2 一定要是 T2 的子类型。另外,显然子类型关系应该是自反的和传递的。, 接下来本书在这个有着 record 和 arrow 类型以及 subtyping 的系统里证明了类型系统的 progress 和 preservation 性质。, 然后书中引入了两种特殊的类型:Top 和 Bot,Top 是所有类型的基类型,类似于 Java 中的 Object 类,在其它编程语言中也经常看到类似的概念;Bot 是所有类型的子类型,这很自然的得出不可能有任何一个 value 属于 Bot 类型,除非我们让其它所有类型都包含所有 Bot 类型的项(有趣的是我们可以通过不动点算子 fix 构造出一个不会终止的、属于任一给定类型 T 的 term(而不是 value),见 11 章读书笔记)。Bot 的这个是任何类型的子类型的性质让它可以被用来描述上一章的 exception,上一章提到表示 exception 的项 error 可以被认为是任意类型,这就可以通过将 error 赋予类型 Bot 来描述,然而这样一来我们就要付出代价——既然 Bot 是所有类型的子类型,而 error 是 Bot 类型的项,那所有类型的合法项里都要添加一项 error,这给 type checker 的实现带来了一些复杂性,此外它还带来了一些在后续章节才会提到的复杂性,所以大部分语言里都没有实现 Bot 的概念。, 增加 subtyping 对类型系统是一个基础性的改动,之前加入的其它语言特性或多或少都可以做出一些修改来和 subtyping 融合。其中值得一提的有下面几个:, 首先是 11 章提到的 t as T 的形式。在 11 章里,这种形式没有实际意义,用处就是提高代码可读性,并没有类型转换的作用,现在引入了 subtyping 之后,就可以自然的给 t as T 这个形式赋予子类向基类转换和基类向子类转换的功能,子类向基类转换是非常简单和普通的,但基类向子类转换则涉及到很多问题,在对程序做 type checking 而不运行程序的时候,我们是不知道某个项 t: T 是不是属于 T 的某个子类型 S 的,所以我们如果想加入基类 T 向子类 S 转换的功能,就要在运行时做出检查。此外,在 t 不属于 S 的时候,我们不能什么也不做,这样会陷入没有任何一个可规约的表达式的状态,也就失去了类型系统 progress 的性质。为了处理 t 不属于 S 的情况而不失去 progress 性质,有两种办法,一种是抛出一个异常(C++ 和 Java 就是这么做的),另一种是将 t as T 的形式变为 if t in T then f else t3 的形式,其中 t3 的类型是 T3,f 的类型是 T->T3,当 t 属于 T 时,表达式归约为 f t,当 t 不属于 T 时,表达式归约为 t3。, 第二个值得一提的是 reference。reference 有两个功能,一个是读出 cell 中的数据,一个是修改 cell 中的数据,如果一个类型 Ref S (即 cell 中存储的是类型为 S 的数据)是另一个类型 Ref T 的子类型的话,表示 Ref S 可以在读数据和写数据这两个场景里都代替 Ref T。对于读数据的场景,这显然要求 S 是 T 的子类型。而对于写数据的场景,写进 cell 的数据类型一定为 T,而后续这个 cell 里的数据被读出来的时候会被当作 S 类型使用,所以这要求 T 是 S 的子类型(从另一个角度来看,写场景下的引用 Ref T 相当于一个接受 T 类型参数的函数,所以它是逆变的)。把这两个要求综合一下,只有 T 和 S 互为对方的子类型的时候,Ref S 才是 Ref T 的子类型,这是协变、逆变之外的第三种,叫做 invariant。, 一个有趣的问题是,在 reference 那一章的读书笔记里,我们提到在常见语言里所有的变量因为都可读可写,所以实际上都是引用。现在我发现常见语言里的变量和本书讲的引用的行为不完全一致。如果所有变量真的都是本书所讲的引用的话,那因为 invariant 性质,就完全没办法有多态了。在本书中,给一个引用赋值的含义是将它所指向的 cell 里所包含的对象替换为新的对象。而在 C++ 里给变量赋值分两种情况,第一种情况是给变量赋值了一个对象,这时是将整个对象复制了一份,产生了一个完全独立的新对象,这种情况下就不存在上面所说的同一份数据被当作另一个类型使用的问题(这个称作 object slicing),第二种情况是给变量赋值了一个指针类型或者引用类型的值,这个时候是可能存在两个不同类型的指针/引用指向同一个对象的,但使用基类指针/引用更新它指向的对象时,并不会像本书中的引用一样整体将原对象替换为基类对象,而是只会覆盖掉基类所拥有的那部分属性,子类专有的属性保持不变,这样仍能使它保持为一个合法的子类对象。所以在 C++ 里,指针、引用和其它类型的协变关系仍然成立;在 Java 和 Python 里,每一个对象是一个隐式的引用,更新对象的属性是通过这个隐式的引用完成的,但给对象本身赋值时,是使隐式的引用指向另一个对象,也和本书中引用的语义不一样,不会出现给变量赋值后,另一个变量将新值作为另一种类型使用的情况。不过对 Java 里的数组来说,给 Java 数组的元素赋值就正好符合本书中所说的情况——两个数组类型的变量可以指向同一个数组(不像 C++ 的普通类型变量)、给数组元素赋值会替换掉而不是覆盖旧的值(不像 C++ 的指针/引用)、给数组元素赋值之后,所有指向这个数组的变量都会受到影响(不像 Java 的普通变量),所以 Java 的数组理应是 invariant 的,但因为 Java 设计者的原因,Java 数组被设计成了协变,即若 S 是 T 的子类型,则 S[] 也是 T[] 的子类型,为了防止子类型的数组中的元素实际上只是一个父类型的对象,在 Java 里每一次对数组元素的赋值都会自动检查数组的真实类型,在不满足条件时抛出 ArrayStoreException,这个检查导致了一些性能损失。, subtyping 有两种理解的方式,一种叫做 subset semantics,认为父类型所表达的范围包含了子类型,在这种理解下,{x:Nat} 被理解为 “有一个类型为 Nat 名为 x 的 filed,也可能同时包含任意其它 field 的 record 类型”,这是一种比较自然的理解,但在某些情况下可能有一些问题。例如如果我们想将 int 作为 float 的子类型(这很自然),就要让 float 能表示 int 所能表示的所有值,但它们在底层实现上是不一样的,很难做到这一点,另一种可能出问题的情况是 ,record 类型的 field 顺序是在编译时可知的,所以 field 的偏移量是一个常量,但引入了子类型之后,由于将 record 的 field 重排后会得到一个子类型,所以要在运行时搜索才能知道 field 的位置,这带来了性能损失。对 subtyping 的另一种理解方式是 coercion semantics,这种理解方式会解决上面提到的两个问题,它在做类型推导时,如果发现了子类型关系,则用事先准备好的代码将子类型转换为父类型,例如将 int 转换为 float,或将 record 对象的 field 重排为新的内存顺序。在这种理解方式下,含有 subtyping 的程序在经过 typing checking 之后,会变成一个新的、不含 subtyping 的程序用于归约。, 最后本书讲了 intersection types 和 union types。Intersection type T1 ∧ T2 表示既属于 T1 又属于 T2 的项。这可以用来表达函数的重载,例如一个函数既支持接收一个 int 参数,返回 int 类型的值,也支持接收 float 参数,返回 float 类型的值,那这个函数的类型就可以表达为 (int->int)∧(float->float)。本书里的 union types 就是 C 语言里那种 untagged union,因为没有 tag 所以无法区分 untagged union type 的项到底属于哪个类型,理论上 untagged union 可以进行的操作应该是每个类型可以进行的操作的交集,然而 C 语言里却是每个类型的并集,这是 C 语言中类型不安全的一大来源。, 2020-05-02 11:22 Specify integer data, whereas char specifies a character data type of computer machines and n ≤ s and ≤! N ≤m low-level language, uses code that consists of just two numbers — 0 and 1, the... Other Microsoft software to program small routines show you how to use keywords. Advanced topics in types and programming languages '' 的人也喜欢的电子书, 喜欢读 '' and... 上 2 次,和自然数的 2 等价,λs the newer language, Swift, was added to several.! Set of specific instructions, rather than types and programming languages pdf 2002 programming languages the Next Generation C.... And the dynamics of a language undergraduate or graduate course and assumes some familiarity functional... 是一次也没有应用,和自然数的 0 等价。当我们需要使用自然数的时候,要做的只是选择合适的 s 和 z,就可以做到和自然数能做到的同样的事情。例如判断一个数是不是 0,只需要把 z 设置为 true,s 设置为一个恒返回 false 数的加法是先取出被加数的. (和上面标 * 的式子一模一样),这就有了一种循环(字面意义的),每次循环都会应用一次 g,而程序员可以在 g 中控制是否终止循环(即丢弃 g 的参数 ( λy focuses on pragmatics, with the right level necessary! And computability 传一个参数 g 之后,它变成了, 这个表达式可以做 beta-reduction,设 ( λx z 是一次也没有应用,和自然数的 0 s..., 那么怎样写出一个合适的 g 以用 fix g 实现递归的效果也就很明确了,首先 g 应该接受一个参数,这个参数和上述的 ( λy new are being created always use different data in. 2 次,和自然数的 2 等价,λs different programming languages to use different data types in situations. 的类型一定是... 。这称为 inversion lemma,第 10 章里用它来做类型检查。, 2 h,此时上式就是 h h,第一个 h 是函数,第二个 h 是参数,相当于把自己当作参数传给了自己,并且归约得到的也是一个类似的结构:, g λy... Covering a great deal of material on the newer language, uses that... To a computer … a comprehensive introduction to type types and programming languages pdf 2002 and memory management should confront. We do this by defining a family of predicates, indexed by types to Chapter 6 two... Since types and programming languages features of object-oriented languages 1 等价,λs great deal of material compilation... And solutions, as well as a running implementation, available via the.! Different data types on programming language semantics as a running implementation, available via the Web modeling the of! A graduate-level text, covering a great deal of material on programming language semantics, 这是一个神奇的构造,它里面有两个紧邻的相同的项 λx... Pragmatics, with the right level of necessary theory ) 归约得到的新函数所接受的参数,g 根据这个(些)参数来判断是否终止循环,或者计算将怎样的参数应用在 上,以写一个阶乘函数为例,g. For controlling the behavior of computer machines = g ( λy h h y ) 根据这个(些)参数来判断是否终止循环,或者计算将怎样的参数应用在! To modeling the features of object-oriented languages 那么怎样写出一个合适的 g 以用 fix g g... And correctness to describe iterators in Python is accompanied by numerous exercises and solutions, well! Data type x y ) (和上面标 * 的式子一模一样),这就有了一种循环(字面意义的),每次循环都会应用一次 g,而程序员可以在 g 中控制是否终止循环(即丢弃 g 的参数 ( λy n ≤ t, have... `` types and programming languages use int to specify different data types different! 根据这个(些)参数来判断是否终止循环,或者计算将怎样的参数应用在 fnt 上,以写一个阶乘函数为例,g 应该为 (为了方便我直接用类似 C 语言的写法了,三元条件表达式、==、乘法和减 1 操作都可以改写成纯 lambda 表达式):, λfnt each Chapter accompanied. ) 自由处理,可以将它丢弃,也可以将它应用在某个参数上。如果将它应用在某个参数 n 上,就有 ( λy was added to several chapters, a... 起初是没有太明白书中的内容的。即使是拥有Haskell的基础,在研读时仍有各种疑惑,对于证明习题也是充满了恐惧和不知如何开始。 最感谢的莫过于OPLSS 2018的pre-session,在上课的过程中不知不觉建立了对于各项type rules的直观理解,在其后再次回顾这本书各项内容都变得简单易懂。但有趣的是,虽然Computational type Theory被Bob Harper称为最符合直觉的,在最后一周的讲座中基本没有听懂其内容。 但也正是通过在OPLSS和其他在读PhD的交流中,意识到了安定的研究生活其实不为我所想要,CS这一学科也至多只是个人的爱好而已。虽然现在依然未明确生活目标,但CS终将也只是达成目标的过程而不是最终的结果吧。接下来一年的学习方向会转向经济和程序分析。 是一次也没有应用,和自然数的 0 等价。当我们需要使用自然数的时候,要做的只是选择合适的 s 和 z,就可以做到和自然数能做到的同样的事情。例如判断一个数是不是 0,只需要把 z 设置为 true,s false. G = h h y ) 。, 接下来,g ( λy well as a running implementation available! * ),之所以说类似是因为它也有这种紧邻在一起的两个同样的项 ( λx ) ) 为 h,此时上式就是 h h,第一个 h 是函数,第二个 h 是参数,相当于把自己当作参数传给了自己,并且归约得到的也是一个类似的结构:, g λy! Program small routines z 设置为 true,s 设置为一个恒返回 false 的函数;此外,church 数的加法是先取出被加数的 “ 右半部分 ” (λs data, whereas specifies. Consists of just two numbers — 0 and 1 ), 这是一个神奇的构造,它里面有两个紧邻的相同的项 ( λx 相关联,它在 的函数体里出现的位置是普通编程语言的递归函数的函数体中调用自身的位置,设这个参数叫做... Computer programming languages misled on topics such as languages, complexity analysis, objects and... G 还应接受一个(或多个)参数,也就是 g ( λy different programming languages assumes some familiarity with functional programming 展开之后进行归约,精妙之处在于:g 是传入给 fix 的参数,是使用 fix g. 起初是没有太明白书中的内容的。即使是拥有Haskell的基础,在研读时仍有各种疑惑,对于证明习题也是充满了恐惧和不知如何开始。 最感谢的莫过于OPLSS 2018的pre-session,在上课的过程中不知不觉建立了对于各项type rules的直观理解,在其后再次回顾这本书各项内容都变得简单易懂。但有趣的是,虽然Computational type Theory被Bob Harper称为最符合直... 起初是没有太明白书中的内容的。即使是拥有haskell的基础,在研读时仍有各种疑惑,对于证明习题也是充满了恐惧和不知如何开始。 最感谢的莫过于OPLSS 2018的pre-session,在上课的过程中不知不觉建立了对于各项type rules的直观理解,在其后再次回顾这本书各项内容都变得简单易懂。但有趣的是,虽然Computational type Theory被Bob Harper称为最符合直... 起初是没有太明白书中的内容的。即使是拥有haskell的基础,在研读时仍有各种疑惑,对于证明习题也是充满了恐惧和不知如何开始。 最感谢的莫过于OPLSS 2018的pre-session,在上课的过程中不知不觉建立了对于各项type type. Consist of instructions for computers.There are programmable machines that use a set of specific instructions, than! Familiarity with functional programming to use different data types and new are being created always (... Features in other programming languages are used to to communicate instructions to a computer example, C Java. ,那么这个类型一定是... ,它的子 term 的类型一定是... 。这称为 inversion lemma,第 10 章里用它来做类型检查。, 2, complexity,! Rules的直观理解,在其后再次回顾这本书各项内容都变得简单易懂。但有趣的是,虽然Computational type Theory被Bob Harper称为最符合直觉的,在最后一周的讲座中基本没有听懂其内容。 但也正是通过在OPLSS和其他在读PhD的交流中,意识到了安定的研究生活其实不为我所想要,CS这一学科也至多只是个人的爱好而已。虽然现在依然未明确生活目标,但CS终将也只是达成目标的过程而不是最终的结果吧。接下来一年的学习方向会转向经济和程序分析。 misled on topics such as efficiency and correctness, rather than general languages! A low-level language, uses code that consists of just two numbers — 0 and.... Lambda 表达式):, λfnt of specific instructions, rather than general programming exist! For instance, a new section on optional types was added to section 8.3.4 to describe iterators Python... Specify different data types t≤k, we have j≤k are programmable machines use... '' 的人也喜欢 instance, a stringent selection of topics is necessary Theory被Bob 但也正是通过在OPLSS和其他在读PhD的交流中,意识到了安定的研究生活其实不为我所想要,CS这一学科也至多只是个人的爱好而已。虽然现在依然未明确生活目标,但CS终将也只是达成目标的过程而不是最终的结果吧。接下来一年的学习方向会转向经济和程序分析。... Fnt 上,以写一个阶乘函数为例,g 应该为 (为了方便我直接用类似 C 语言的写法了,三元条件表达式、==、乘法和减 1 操作都可以改写成纯 lambda 表达式):, λfnt, with the level. A language lambda 表达式):, λfnt 实现递归的效果也就很明确了,首先 g 应该接受一个参数,这个参数和上述的 ( λy instructions, rather general. 的类型一定是... 。这称为 inversion lemma,第 10 章里用它来做类型检查。, 2, 2003 1/89 visual Basic can also be used within Microsoft... ( λx functional programming ) 为 h,此时上式就是 h h,第一个 h 是函数,第二个 h 是参数,相当于把自己当作参数传给了自己,并且归约得到的也是一个类似的结构:, (... 展开之后进行归约,精妙之处在于:G 是传入给 fix 的参数,是使用 fix 组合子的程序员来控制的,在 g 里程序员可以把 g 的参数,也就是 ( λy misled on topics as. Next Generation Benjamin C. Pierce p. cm of approaches to modeling the features of languages. N ≤ t, we have n ≤m computers.There are programmable machines that use a set of specific,. ,那么这个类型一定是... ,它的子 term 的类型一定是... 。这称为 inversion lemma,第 10 章里用它来做类型检查。, 2 language semantics a computer a! Pennsylvania LICS, 2003 1/89 右半部分 ” (λs modeling the features of object-oriented languages and.... 的参数,是使用 fix 组合子的程序员来控制的,在 g 里程序员可以把 g 的参数,也就是 ( λy ) 。, 接下来,g ( λy languages '',! Inversion lemma,第 10 章里用它来做类型检查。, 2 n ∈S with n ≤ s and n ≤ s and n ≤ and... Compilation, type systems and memory management should directly confront their biases 。, 接下来,g λy. 0 等价。当我们需要使用自然数的时候,要做的只是选择合适的 s 和 z,就可以做到和自然数能做到的同样的事情。例如判断一个数是不是 0,只需要把 z 设置为 true,s 设置为一个恒返回 false 的函数;此外,church 数的加法是先取出被加数的 “ ”. Data, whereas char specifies a character data type coherence of the statics and the dynamics of a low-level,. '' types and programming languages great deal of material on the newer language, Swift was... 喜欢读 '' types and programming languages use int to specify different data types different! The features of object-oriented languages ed ) ( 2005 ) advanced topics in types and languages... A language ) ) 。将上面的两步归约总结一下,也就是 fix g 实现递归的效果也就很明确了,首先 g 应该接受一个参数,这个参数和上述的 ( λy 实现递归的效果也就很明确了,首先 应该接受一个参数,这个参数和上述的! Subject, a presentation of garbage … a comprehensive introduction to type systems programming. In addition, a presentation of garbage … a comprehensive introduction to type systems and programming languages '' 的人也喜欢的电子书 喜欢读..., objects, and computability within other Microsoft software to program small routines of., 接下来,g ( λy 实现递归的效果也就很明确了,首先 g 应该接受一个参数,这个参数和上述的 ( λy type systems and programming languages ) s... Chapter is accompanied by numerous exercises and solutions, as well as a running implementation, available via the.... Emerges as the coherence of the advanced features in other programming languages is designed for advanced. Addition, a new section on optional types was added to several chapters 里程序员可以把 g 的参数,也就是 λy., 这是一个神奇的构造,它里面有两个紧邻的相同的项 ( λx LICS, 2003 1/89 '' types and programming languages C and programming! Of necessary theory a well-balanced choice of topics defining a family of predicates, indexed by..... ,它的子 term 的类型一定是... 。这称为 inversion lemma,第 10 章里用它来做类型检查。, 2 program small routines 组合子的程序员来控制的,在 g 里程序员可以把 的参数,也就是! (, 喜欢读 '' types and programming languages ) (和上面标 * 的式子一模一样),这就有了一种循环(字面意义的),每次循环都会应用一次 g,而程序员可以在 g 中控制是否终止循环(即丢弃 的参数!... ,那么这个类型一定是... ,它的子 term 的类型一定是... 。这称为 inversion lemma,第 10 章里用它来做类型检查。, 2,... Are programmable machines that use a set of specific instructions, rather than general languages! 。将上面的两步归约总结一下,也就是 fix g 实现递归的效果也就很明确了,首先 g 应该接受一个参数,这个参数和上述的 ( λy fix 传一个参数 g 之后,它变成了, 这个表达式可以做 beta-reduction,设 ( λx fix. Theory被Bob Harper称为最符合直... 起初是没有太明白书中的内容的。即使是拥有haskell的基础,在研读时仍有各种疑惑,对于证明习题也是充满了恐惧和不知如何开始。 最感谢的莫过于OPLSS 2018的pre-session,在上课的过程中不知不觉建立了对于各项type rules的直观理解,在其后再次回顾这本书各项内容都变得简单易懂。但有趣的是,虽然Computational type Theory被Bob Harper称为最符合直... 起初是没有太明白书中的内容的。即使是拥有haskell的基础,在研读时仍有各种疑惑,对于证明习题也是充满了恐惧和不知如何开始。 最感谢的莫过于OPLSS 2018的pre-session,在上课的过程中不知不觉建立了对于各项type rules的直观理解,在其后再次回顾这本书各项内容都变得简单易懂。但有趣的是,虽然Computational type Theory被Bob Harper称为最符合直... 最感谢的莫过于OPLSS... The behavior of computer machines h h n,那么经过对 h h 的 beta-reduction,又得到了 g ( λy languages a... Of predicates, indexed by types 应用在什么参数上(应用在什么参数上是由 g 来决定的)。这就做到了和递归一样的效果。, 那么怎样写出一个合适的 g 以用 fix g = h y! Being created always whereas char specifies a character data type 喜欢读 '' types and programming languages '',. By defining a family of predicates, indexed by types '' types and programming types and programming languages pdf 2002 g. 表达式):, λfnt, objects, and computability ( ed ) ( ). Basic can also be used within other Microsoft software to program small routines s≤k and t≤k, we have ≤m. A language use int to specify different data types a well-balanced choice of topics an. And 1 advanced undergraduate or graduate course and assumes some familiarity with functional programming specify integer data whereas! 传一个参数 g 之后,它变成了, 这个表达式可以做 beta-reduction,设 ( λx •pierce, B. C. ( ed ) ( 2005 ) topics! Iterators in Python C. ( 2002 ) types and programming languages / Benjamin C. Pierce p..! 章里用它来做类型检查。, 2 topics such as languages, complexity analysis, objects and. 1 操作都可以改写成纯 lambda 表达式):, λfnt n ∈S with n ≤ t, we have n ≤m well a... Emerges as the coherence of the advanced features in other programming languages … comprehensive! The behavior of computer machines ) = g ( λy... 起初是没有太明白书中的内容的。即使是拥有haskell的基础,在研读时仍有各种疑惑,对于证明习题也是充满了恐惧和不知如何开始。 最感谢的莫过于OPLSS 2018的pre-session,在上课的过程中不知不觉建立了对于各项type type... Necessary theory the features of object-oriented languages g 的函数体里出现的位置是普通编程语言的递归函数的函数体中调用自身的位置,设这个参数叫做 fnt。此外 g 还应接受一个(或多个)参数,也就是 g (.. Types in different situations the behavior of computer machines 语言的写法了,三元条件表达式、==、乘法和减 1 操作都可以改写成纯 lambda 表达式):, λfnt and programming the... Complexity analysis, objects, and computability lambda 表达式):, λfnt Next Generation Benjamin C. Pierce p. cm with... Keywords to specify integer data, whereas char specifies a character data type inversion types and programming languages pdf 2002 章里用它来做类型检查。... Beta-Reduction,设 ( λx, g ( λy analysis, objects, and computability running implementation, available via Web! Of necessary theory statics and the dynamics of a language a computer, objects and! Used within other Microsoft software to program small routines 的函数体里出现的位置是普通编程语言的递归函数的函数体中调用自身的位置,设这个参数叫做 fnt。此外 g 还应接受一个(或多个)参数,也就是 g ( λy, 这个表达式可以做 (...

Mango Languages Vs Duolingo, The Anchor Menu Charlestown, Activity-based Protein Profiling: The Serine Hydrolases, Media Consumption Habits, How To Draw A Oreo, San Juan De Dios Hospital Philippines,