A---calculus with Constants and Let-blocks.ppt
《A---calculus with Constants and Let-blocks.ppt》由会员分享,可在线阅读,更多相关《A---calculus with Constants and Let-blocks.ppt(26页珍藏版)》请在麦多课文档分享上搜索。
1、A-calculus with Constants and Let-blocks,September 19, 2006,September 19, 2006,http:/www.csg.csail.mit.edu/6.827,Outline,Recursion and Y combinator The llet Calculus,September 19, 2006,http:/www.csg.csail.mit.edu/6.827,Recursion,fact can be rewritten as: fact = n. Cond (Zero? n) 1 (Mul n (fact (Sub
2、n 1)How to get rid of the fact on the RHS?,fact n = if (n = 0) then 1else n * fact (n-1),Idea: pass fact as an argument to itself,Self application!,H = f.n.Cond (Zero? n) 1 (Mul n (f f (Sub n 1),fact = H H,September 19, 2006,http:/www.csg.csail.mit.edu/6.827,Self-application and Paradoxes,Self appli
3、cation, i.e., (x x) is dangerous. Suppose:u y. if (y y) = a then b else a What is (u u) ?,(u u) if (u u) = a then b else aContradiction!Any semantics of -calculus has to make sure that functions such as u have the meaning , i.e. “totally undefined” or “no information”.Self application also violates
4、every type discipline.,September 19, 2006,http:/www.csg.csail.mit.edu/6.827,Recursion and Fixed Point Equations,Recursive functions can be thought of as solutions of fixed point equations:fact = n. Cond (Zero? n) 1 (Mul n (fact (Sub n 1),SupposeH = f.n.Cond (Zero? n) 1 (Mul n (f (Sub n 1)thenfact =
5、H factfact is a fixed point of function H!,September 19, 2006,http:/www.csg.csail.mit.edu/6.827,Fixed Point Equations,f : D D A fixed point equation has the form f(x) = x,Examples: f: Int Int Solutionsf(x) = x2 2f(x) = x2 + x + 1f(x) = x,x = 2, x = -1,no solutions,infinite number of solutions,Its so
6、lutions are called the fixed points of f because if xp is a solution thenxp = f(xp) = f(f(xp) = f(f(f(xp) = .,September 19, 2006,http:/www.csg.csail.mit.edu/6.827,Least Fixed Point,Consider f n = if n=0 then 1else (if n=1 then f 3 else f (n-2) H = f.n.Cond(n=0 , 1, Cond(n=1, f 3, f (n-2) Is there an
7、 fp such that fp = H fp ?,f1 n = 1 if n is even= otherwise,f1 contains no arbitrary information and is called the least fixed point. Unique solution!,f2 n = 1 if n is even= 5 otherwise,September 19, 2006,http:/www.csg.csail.mit.edu/6.827,Y : A Fixed Point Operator,Notice Y F x.F (x x) (x.F (x x)F (Y
8、 F) ,Y f.(x. (f (x x) (x.(f (x x),F (x.F (x x) (x.F (x x),F (x.F (x x) (x.F (x x),F (Y F) = Y F (Y F) is a fixed point of FY computes the least fixed point of any function !There are many different fixed point operators.,September 19, 2006,http:/www.csg.csail.mit.edu/6.827,Mutual Recursion,odd = H1
9、even even = H2 oddwhere H1 = f.n.Cond(n=0, False, f(n-1)H2 = f.n.Cond(n=0, True, f(n-1),odd n = if n=0 then False else even (n-1) even n = if n=0 then True else odd (n-1),substituting “H2 odd” for even odd = H1 (H2 odd) = H odd where H = odd = Y H,f. H1 (H2 f),Can we expressing odd using Y ?,Septemb
10、er 19, 2006,http:/www.csg.csail.mit.edu/6.827,-calculus with Combinator Y,Recursive programs can be translated into the -calculus with constants and Y combinator. However, Y combinator violates every type disciplinetranslation is messy in case of mutually recursive functions extend the -calculus wit
11、h recursive let blocks.,September 19, 2006,http:/www.csg.csail.mit.edu/6.827,Outline,Recursion and Y combinator The llet Calculus ,September 19, 2006,http:/www.csg.csail.mit.edu/6.827,-calculus with Constants & Letrec,E := x | x.E | E E | Cond (E, E, E) | PFk(E1,.,Ek) | CN0 | CNk(E1,.,Ek) | CNk(SE1,
12、.,SEk) | let S in E PF1 := negate | not | . | Prj1| Prj2 | . PF2 := + | . CN0 := Number | Boolean CN2 := cons | .Statements S := | x = E | S; SVariables on the LHS in a let expression must be pairwise distinct,not in initial terms,September 19, 2006,http:/www.csg.csail.mit.edu/6.827,Let-block Statem
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ACALCULUSWITHCONSTANTSANDLETBLOCKSPPT
