函数式编程:可执行规范和程序转换

S. Thompson
{"title":"函数式编程:可执行规范和程序转换","authors":"S. Thompson","doi":"10.1145/75199.75244","DOIUrl":null,"url":null,"abstract":"In this paper we give an example of the use of functional programming language in the specification and development of a program to solve a non-trivial problem. In particular, we show how we can give a direct implementation of a constructive specification (an execuiable specification, in other words) and then show how program transformation can be used to turn this specification into an efficient version of the program, using techniques from a standard library of transformations. We introduce the paper with a short review of functional programming. 1 Functional Programming In this section we introduce the major ideas of functional programming, as exemplified by Miranda ‘[4], (pure) ML [5] and various other languages ([3]). The language which we use here is Miranda, in fact. The process underlying functional programming is one which we learn in elementary school, before we are exposed to micros, BASIC e2 al.. This is the process of calculation. Given an expression like (2 + 3)/(7 2) we learn that we first have to evaluate the sub-expressions (2+3) and (7-2), and then apply the operator ‘1’. This is exactly what we do when we run a functional program we calculate the value of an expression, which may involve operators or functions which are defined by the user. Consider an example. To work out the sum of squares of the first hundred positive integers, we calculate the value of sum-of -squares loowhere sum-of-squares n = n*n t sum-of-squares (n-1) , 01 = 1 , otherwise Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission. This operator describes what the sum is, in a natural way if n is greater than one, we square it and add it to the sum up to n-l, if not, the answer is immediate one. Observe that we can read the above not only as a definition, but also a property of the function sum-of-squares. Function definitions are their own descriptions. This is not true of imperative languages, in which a program description has to be written in a logic separate from the language itself. Take an example of evaluation, in which we abbreviate sum-of-squares by SOS: SOS 3 = 3*3 + (SOS 2)","PeriodicalId":435917,"journal":{"name":"International Workshop on Software Specification and Design","volume":"15 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"1989-04-01","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"9","resultStr":"{\"title\":\"Functional programming: executable specifications and program transformations\",\"authors\":\"S. Thompson\",\"doi\":\"10.1145/75199.75244\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"In this paper we give an example of the use of functional programming language in the specification and development of a program to solve a non-trivial problem. In particular, we show how we can give a direct implementation of a constructive specification (an execuiable specification, in other words) and then show how program transformation can be used to turn this specification into an efficient version of the program, using techniques from a standard library of transformations. We introduce the paper with a short review of functional programming. 1 Functional Programming In this section we introduce the major ideas of functional programming, as exemplified by Miranda ‘[4], (pure) ML [5] and various other languages ([3]). The language which we use here is Miranda, in fact. The process underlying functional programming is one which we learn in elementary school, before we are exposed to micros, BASIC e2 al.. This is the process of calculation. Given an expression like (2 + 3)/(7 2) we learn that we first have to evaluate the sub-expressions (2+3) and (7-2), and then apply the operator ‘1’. This is exactly what we do when we run a functional program we calculate the value of an expression, which may involve operators or functions which are defined by the user. Consider an example. To work out the sum of squares of the first hundred positive integers, we calculate the value of sum-of -squares loowhere sum-of-squares n = n*n t sum-of-squares (n-1) , 01 = 1 , otherwise Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission. This operator describes what the sum is, in a natural way if n is greater than one, we square it and add it to the sum up to n-l, if not, the answer is immediate one. Observe that we can read the above not only as a definition, but also a property of the function sum-of-squares. Function definitions are their own descriptions. This is not true of imperative languages, in which a program description has to be written in a logic separate from the language itself. Take an example of evaluation, in which we abbreviate sum-of-squares by SOS: SOS 3 = 3*3 + (SOS 2)\",\"PeriodicalId\":435917,\"journal\":{\"name\":\"International Workshop on Software Specification and Design\",\"volume\":\"15 1\",\"pages\":\"0\"},\"PeriodicalIF\":0.0000,\"publicationDate\":\"1989-04-01\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"9\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"International Workshop on Software Specification and Design\",\"FirstCategoryId\":\"1085\",\"ListUrlMain\":\"https://doi.org/10.1145/75199.75244\",\"RegionNum\":0,\"RegionCategory\":null,\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"\",\"JCRName\":\"\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"International Workshop on Software Specification and Design","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/75199.75244","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 9

摘要

在本文中,我们给出了一个使用函数式编程语言来说明和开发一个程序来解决一个非平凡问题的例子。特别地,我们展示了如何给出一个建设性规范(换句话说,一个可执行的规范)的直接实现,然后展示了如何使用程序转换,使用转换标准库中的技术,将该规范转换为程序的有效版本。我们通过对函数式编程的简要回顾来介绍本文。在本节中,我们将介绍函数式编程的主要思想,例如Miranda的[4]、(纯)ML[5]和各种其他语言([3])。事实上,我们在这里使用的语言是米兰达。函数式编程的基本过程是我们在小学学习的,在我们接触到micros, BASIC等之前。这就是计算的过程。给定一个像(2+3)/(7 2)这样的表达式,我们知道我们首先必须计算子表达式(2+3)和(7-2),然后应用运算符“1”。这正是我们在运行函数式程序时所做的:计算表达式的值,其中可能包含用户定义的操作符或函数。考虑一个例子。为了计算出前100个正整数的平方和,我们计算平方和的值,其中平方和n = n*n t平方和(n-1), 01 = 1,否则,允许免费复制全部或部分本材料,前提是复制不是为了直接商业利益而制作或分发,ACM版权声明以及出版物的标题和日期出现。并注明复制是由计算机协会许可的。以其他方式复制或重新发布需要付费和/或特定许可。这个算子描述了和是什么,用一种自然的方式如果n大于1,我们对它平方,然后加到和上,等于n- 1,如果不是,答案就是1。注意,我们不仅可以把上面的定义看作是平方和函数的性质,而且可以看作是平方和函数的性质。函数定义是它们自己的描述。命令式语言不是这样的,在命令式语言中,程序描述必须用与语言本身分离的逻辑编写。以求值为例,我们将平方和缩写为SOS: SOS 3 = 3*3 + (SOS 2)
本文章由计算机程序翻译,如有差异,请以英文原文为准。
Functional programming: executable specifications and program transformations
In this paper we give an example of the use of functional programming language in the specification and development of a program to solve a non-trivial problem. In particular, we show how we can give a direct implementation of a constructive specification (an execuiable specification, in other words) and then show how program transformation can be used to turn this specification into an efficient version of the program, using techniques from a standard library of transformations. We introduce the paper with a short review of functional programming. 1 Functional Programming In this section we introduce the major ideas of functional programming, as exemplified by Miranda ‘[4], (pure) ML [5] and various other languages ([3]). The language which we use here is Miranda, in fact. The process underlying functional programming is one which we learn in elementary school, before we are exposed to micros, BASIC e2 al.. This is the process of calculation. Given an expression like (2 + 3)/(7 2) we learn that we first have to evaluate the sub-expressions (2+3) and (7-2), and then apply the operator ‘1’. This is exactly what we do when we run a functional program we calculate the value of an expression, which may involve operators or functions which are defined by the user. Consider an example. To work out the sum of squares of the first hundred positive integers, we calculate the value of sum-of -squares loowhere sum-of-squares n = n*n t sum-of-squares (n-1) , 01 = 1 , otherwise Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission. This operator describes what the sum is, in a natural way if n is greater than one, we square it and add it to the sum up to n-l, if not, the answer is immediate one. Observe that we can read the above not only as a definition, but also a property of the function sum-of-squares. Function definitions are their own descriptions. This is not true of imperative languages, in which a program description has to be written in a logic separate from the language itself. Take an example of evaluation, in which we abbreviate sum-of-squares by SOS: SOS 3 = 3*3 + (SOS 2)
求助全文
通过发布文献求助,成功后即可免费获取论文全文。 去求助
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术官方微信