文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > A Denotational Approach to Measuring Complexity in Functional Programs
侵权投诉

A Denotational Approach to Measuring Complexity in Functional Programs

A Denotational Approach to Measuring Complexity in Functional Programs

1.3. EVALUATION STRATEGIES cost of the length function that computes the length of a list is

5

n(t++ ttail+ tfalse)+ (n+ 1)(tnil?+ tapp+ trec)+ ttrue where n is the actual length of the list, and the costs represent the major actions of applying a function (tapp ), unrolling a recursive de nition (trec), tak

ing the tail of a list (ttail), taking either the false (tfalse) or true (ttrue) branches of a conditional, and adding two integers (t+ ). From this information we can determine that the time it takes to run length is O(n), i.e., is proportional to the length of the list.

1.3 Evaluation Strategies When evaluating an application, there is more than one way to handle the argument. The argument could be evaluated rst and the result handed to the calling function. This type of evaluation is called strict or call-by-value . Alternatively, the argument could be saved and evaluated only when needed. If the argument is evaluated every time it is needed, the evaluation strategy is called call-by-name . If the result of evaluating the argument is saved so reevaluation is not necessary, the evaluation strategy is called call-by-need . Thus when evaluating the expression (lam x:lam y:x+ x) e1 e2 The expression e1 is evaluated once for call-by-value and call-by-need, but twice for call-by-name, while the expression e2 is evaluated once by call-by-value, and not at all by call-by-need and call-byname. If it takes a lot of time to evaluate e1, then the call-by-value and the call-by-need strategies will take signi cantly less time to evaluate the overall expression. On the other hand, if it takes a long time to evaluation e2, then the call-by-name and call-by-need evaluations strategies will be faster than the call-by-value. It would thus seem that the call-by-need evaluation strategy would always be the most e cient. In practice, however, there is considerable overhead and complexity involved in keeping track of unevaluated expressions and updating the results of evaluation. For that reason there are many functional languages (e.g., Lisp, SML) that implement call-by-value evaluation. Even those languages that implement call-by-need (e.g., Haskell, Miranda) will often use strictness analysis to determine which arguments will always be evaluated, and use call-by-value evaluation on those arguments.

1.4 The Semantics The goal of this work is the development of a denotational pro ling semantics of higher-order strict and non-strict functional languages in order to analyze complexity behavior of programs in such languages. We are particularly interested in describing the costs of programs where part of the computation is delayed| either because an argument is needed or because a data type is lazy. The speci c language in use throughout this work is relatively simple| essentially the -calculus with conditionals, recursion, and constants. This language is a generalization of PCF ( 39]) in that we do not explicitly de ne the constants. It will be analyzed under two evaluation strategies: call-by-value and call-by-name. We discuss possibilities for analysis under call-by-need evaluation in section 6.2.4. The desired semantics for the language under both evaluation strategies will satisfy the following properties:

上一页第19页

你可能喜欢

热门文档

相关文档

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email