- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Lecture #14, Feb. 28, 2007.ppt
Lecture #14, Feb. 28, 2007 Type Checkers in ML To build type-checkers in ML we need A datatype to represent types A datatype (or datatypes) to represent programs (whose type we are checking) Expressions Statements Declarations A means for computing equality over types A means for expressing type errors We build type checkers as attribute computations We need to think ahead. An attribute computation for each datatype representing programs What are the inherited and synthesized attributes for each datatype What will the type of the functions that implement each attribute computation. Will we simply compute a type, or will we decorate the syntax tree? The role of type rules Type rules play an important role. They are short and concise They are used as a communication mechanism. S |- x : a S |- f : a - t S |- f x : t Normally, the context is an inherited attribute, and the result is a synthesized attribute Representing Types datatype MLtype = Unit | Int | Char | Bool | Product of MLtype list | Arrow of (MLtype * MLtype); Representing Programs 1 datatype Op = Plus | Less | And datatype Constant = Cint of int (* 5 *) | Cchar of char (* #”z” *) | Cbool of bool (* true *) and Dec = Valdec of string*Exp (* let val x = 5 in x end *) | Fundec of string*string*MLtype*Exp (* let fun f (x:int) = x + 1 in f end *) Representing Programs 2 datatype Exp = Lit of Constant (* 5 *) | Var of string (* x *) | App of Exp*Exp (* f x *) | Tuple of Exp list (* (x,3,true) *) | Infix of Exp*Op*Exp (* x+3 *) | Stmt of Exp list (* (print x; 3) *) | If of Exp * Exp * Exp (* if x then y else 3 *) | While of Exp * Exp (* while x do (f x) *) | Anonfun of string * MLtype * Exp (* (fn x = x+1) *) | Let of Dec*Exp (* let val x = 1 in x end *) Type Equality fun typeeq (x,y) = case
您可能关注的文档
- Computing 3-view GeometryClass 18.ppt
- COMS W4205 Combinatorial Methods.ppt
- Concepts and Operational Definitions.ppt
- Connecticut Geospatial Information Systems Council.ppt
- Consumer Council-考察是.ppt
- Continuous Assessment03162006.ppt
- Contraception.ppt
- CoolingChapter 13.ppt
- COPDChronic Obstructive Lung Disease.ppt
- Copyright © 2008 W. W. Norton & Company.All rights reserved..ppt
- Lecture #18 Class Discussion CP Group Case.ppt
- Lecture 13 Cache and Virtual Memroy Review.ppt
- Lecture 13 Chi-square and sample variance.ppt
- Lecture 13 Competition and Pricing.ppt
- Lecture 13 VHDL Structural Modeling.ppt
- Lecture 13. Dissipation of Gravity Waves.ppt
- Lecture 13.ppt
- Lecture 13Chapter 7 Deadlocks.ppt
- Lecture 13Examples of Memory Management.ppt
- Lecture 13Heteroskedasticity.ppt
文档评论(0)