南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)10_Simply-Typed Lambda Calculus

Simply-Typed Lambda Calculus (Slides made by Hongjin Liang, mostly following Dan Grossman's teaching materials)
Simply-Typed Lambda Calculus (Slides made by Hongjin Liang, mostly following Dan Grossman’s teaching materials)

Review of untyped A-calculus Syntax:notation for defining functions (Terms)M,N :x Ax.MM N Semantics:reduction rules (x.M)N→M[W/x B) M→M' N-N' M→M' MN→M'N MN→MN' λx.M→λX.M
Review of untyped -calculus • Syntax: notation for defining functions (Terms) M, N ::= x | x. M | M N • Semantics: reduction rules λ𝑥. 𝑀 𝑁 → 𝑀[𝑁/𝑥] () 𝑀 → 𝑀′ 𝑀 𝑁 → 𝑀′𝑁 𝑀 → 𝑀′ λ𝑥. 𝑀 → λ𝑥. 𝑀′ 𝑁 → 𝑁′ 𝑀 𝑁 → 𝑀 𝑁′

x.M0N-→M[N/x] (β) M→M' (f.入z.f(fz)(y.y+x) MN→M'N →入z.(y.y+x)(y.y+x)z) N→N' MN→MN' -→入z.(y.y+x)(z+x) M→M' >入z.Z+X+X λX.M→λX.M
(f. z. f (f z)) (y. y+x) → z. (y. y+x) ((y. y+x) z) → z. (y. y+x) (z+x) → z. z+x+x λ𝑥. 𝑀 𝑁 → 𝑀[𝑁/𝑥] () 𝑀 → 𝑀′ 𝑀 𝑁 → 𝑀′𝑁 𝑀 → 𝑀′ λ𝑥. 𝑀 → λ𝑥. 𝑀′ 𝑁 → 𝑁′ 𝑀 𝑁 → 𝑀 𝑁′

Review of untyped A-calculus (Ax.Xx)(7X.xx) >(2x.xx)(x.×x) 〉… This class:adding a type system (We will see that well-typed terms in STLC always terminate.)
Review of untyped -calculus (x. x x) (x. x x) → (x. x x) (x. x x) → … This class: adding a type system (We will see that well-typed terms in STLC always terminate.)

Why types Type checking catches "simple"mistakes early ·Example:2+true+“a” .(Type safety)Well-typed programs will not go wrong Ensure execution never reach a "meaningless"state But"meaningless"depends on the semantics(each language typically defines some as type errors and others run-time errors) Typed programs are easier to analyze and optimize Compilers can generate better code (e.g.access components of structures by known offset) Cons:impose constraints on the programmer Some valid programs might be rejected
Why types • Type checking catches “simple” mistakes early • Example: 2 + true + “a” • (Type safety) Well-typed programs will not go wrong • Ensure execution never reach a “meaningless” state • But “meaningless” depends on the semantics (each language typically defines some as type errors and others run-time errors) • Typed programs are easier to analyze and optimize • Compilers can generate better code (e.g. access components of structures by known offset) Cons: impose constraints on the programmer • Some valid programs might be rejected

Why formal type systems Many typed languages have informal descriptions of the type systems (e.g.,in language reference manuals) A fair amount of careful analysis is required to avoid false claims of type safety A formal presentation of a type system is a precise specification of the type checker And allows formal proofs of type safety
Why formal type systems • Many typed languages have informal descriptions of the type systems (e.g., in language reference manuals) • A fair amount of careful analysis is required to avoid false claims of type safety • A formal presentation of a type system is a precise specification of the type checker • And allows formal proofs of type safety

What we will study about types ·Type system Typing rules:assign types to terms Type safety(soundness of typing rules):well-typed terms cannot go wrong Connection to constructive propositional logic ·Curry-Howard isomorphism:“Propositions are Types'”, “Proofs are Programs
What we will study about types • Type system • Typing rules: assign types to terms • Type safety (soundness of typing rules): well-typed terms cannot go wrong • Connection to constructive propositional logic • Curry-Howard isomorphism: “Propositions are Types”, “Proofs are Programs

Simply-typed A-calculus(STLC) base type (e.g.int,bool) function type (Types)t,o=T|o→t An infinite number of types: int-→int,int→(int→int),(int->int)>int, →is right-associative:t→t→tist→(t→t)
Simply-typed -calculus (STLC) (Types) , ::= T | → base type (e.g. int, bool) function type An infinite number of types: int → int, int → (int → int), (int → int) → int, … → is right-associative: → → is → ( → )

Simply-typed A-calculus(STLC) (Types)t,o=T|o→t (Terms)M,N ::xx t.M MN
Simply-typed -calculus (STLC) (Terms) M, N ::= x | x : . M | M N (Types) , ::= T | →

Reduction rules (x:t.M)N→M[N/x] (β) M→M' MN→M'N Same as untyped A-calculus N→N' MN→MN' M→M' X:t.M→λx:t.M1
Reduction rules λ𝑥: 𝜏. 𝑀 𝑁 → 𝑀[𝑁/𝑥] 𝑀 → 𝑀′ 𝑀 𝑁 → 𝑀′𝑁 𝑀 → 𝑀′ λ𝑥: 𝜏. 𝑀 → λ𝑥: 𝜏. 𝑀′ 𝑁 → 𝑁′ 𝑀 𝑁 → 𝑀 𝑁′ Same as untyped -calculus ()
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)Separation Logic(3/3).ppt
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)Separation Logic(2/3).ppt
- 《程序设计语言的形式语义》课程教学资源(文献资料)An Introduction to Separation Logic(Preliminary Draft).pdf
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)09_Shared-Variable Concurrency.pdf
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)Separation Logic(1/3).ppt
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)07_Axiomatic Semantics and Hoare Logic.pdf
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)06_Denotational Semantics.pdf
- 《程序设计语言的形式语义》课程教学资源(文献资料)Lecture Notes on the Lambda Calculus.pdf
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)05_Operational Semantics.pdf
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)04_Lambda Calculus.pptx
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)03_Math.pdf
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)02_CoqOverview.pptx
- 南京大学:《程序设计语言的形式语义》课程教学资源(课件讲稿)01_Introduction(主讲:冯新宇)Formal Semantics of Programming Languages.ppt
- 私立华联学院:《html5》课程教学资源(课件讲稿)第9章 CSS3高级应用.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第8章 多媒体技术.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第7章 表单的应用.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第6章 浮动与定位.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第5章 CSS盒子模型.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第4章 CSS3选择器.pdf
- 私立华联学院:《html5》课程教学资源(课件讲稿)第3章 CSS3入门.pdf
- 私立华联学院:《C语言程序设计》课程教学资源(教案讲义)教学大纲.pdf
- 私立华联学院:《C语言程序设计》课程教学资源(教案讲义)应用案例.pdf
- 私立华联学院:《C语言程序设计》课程教学资源(教案讲义)课程标准(适用专业:物联网应用技术).pdf
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第一章 初识C语言(负责人:周鹏梅).ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第三章 结构化程序设计.ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第二章 数据类型与运算符.ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第七章 结构体和共同体.ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第五章 函数.ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第八章 文件.ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第六章 指针.ppt
- 私立华联学院:《C语言程序设计》课程电子教案(PPT课件)第四章 数组.ppt
- 私立华联学院:《Python语言程序设计》课程教学资源(教案讲义)课程标准(适用专业:软件技术).pdf
- 私立华联学院:《Python语言程序设计》课程教学资源(教案讲义)课程教学设计(负责人:尹菡).pdf
- 《Python语言程序设计》课程教学资源(拓展资源)Python练习实例(Python 100例).pdf
- 《Python语言程序设计》课程教学资源(拓展资源)零基础Python上手编程(2020版).pdf
- 私立华联学院:《Python语言程序设计》课程教学资源(实习实验)Python编程基础实验指导手册.pdf
- 《Python语言程序设计》课程教学资源(教案讲义)Python学习参考教材(共十一单元).pdf
- 私立华联学院:《Python语言程序设计》课程教学资源(PPT课件)第1单元 初识Python的世界(负责人:尹菡).pptx
- 私立华联学院:《Python语言程序设计》课程教学资源(PPT课件)第2单元 Python基础知识.pptx
- 私立华联学院:《Python语言程序设计》课程教学资源(PPT课件)第3单元 Python字符串输入输出.pptx