文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > 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

Chapter 1

Introduction Early low-level programming languages closely imitated the actions of the computer to simplify the translation of a program into machine instructions. Over time, however, our ability to translate programs has become more sophisticated, resulting in a number of programming languages designed to more closely match a speci cation of the desired result rather than a set of instructions. In particular, functional languages are designed so that programs resemble mathematical speci cations more than machine instructions. Because of this property, it is often clear that a program will always return a correct result, but it may be more di cult to understand those internal properties that closely relate to machine instructions, such as the amount of time a program takes to run or the amount of memory needed in the process. Functional languages typically share a number of properties. Perhaps the most important property of a functional language is the applicative structure of programs. Programs in a\pure" functional language typically consist of a series of function de nitions. There are no assignment statements; instead of for or while loops a programmer uses recursion. Even in\impure" functional languages that also include assignment statements, programs are frequently written in such a style that assignments are the exception rather than the rule. Another important aspect of functional programs is their treatment of functions as\ rst-class citizens." Many imperative languages treat procedures and functions di erently from other data such as integers; for example, one cannot necessarily store a procedure in an array. In a functional language, however, functions are treated as data just as integers or lists are and can be passed to other functions as parameters, returned as results, or used as part of a data structure such as a list or tree. Apart from the simplicity (in concept) of treating all data types equally, such languages have several advantages. One is the ability to de ne general functions that manipulate data structures and then use them to create a wide variety of programs. For example, map applies a function to each element of a list; thus whenever we want a program that performs some conversion on each element of a list, we can simply use map. The function map is also polymorphic in that its behavior can be used for lists of any type (relative to the mapped function) and its behavior is essentially the same in each case. Another advantage is to be able to partially evaluate a procedure by applying it to some but not all of its arguments. The result is a procedure or function that takes the rest of the arguments. This can result in savings when a procedure is called many times with many of the same arguments. There are some functional languages where functions are not rst-class citizens; in particular,

they do not allow functions to take other functions as arguments. Such languages are considered\functional" primarily because they do not allow assignments. These languages are called rstorder functional languages; functional languages that allow functions as arguments are then called 1

上一页第15页

你可能喜欢

热门文档

相关文档

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