{"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}
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)