
函数程序设计.ppt
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 函数程序设计.ppt
- 资源描述:
-
1、函数程序设计 Functional Programming http:/ 海燕 020-31981361,Important links,All about the course: http:/ All about Haskell: http:/haskell.org,课程安排与要求,每周二1214节,213周; 地点:实验室B202 讲义:Haskell函数程序设计; 成绩评定:平时成绩50% + 期末成绩50%,平时成绩包括 课堂参与; 课堂、课下作业; 要求:认真对待“选修课”,选修/=不重要;共同保证这两个学分的质量。,函数程序设计简介,函数程序设计语言的历史背景 什么是函数程序设计
2、 函数程序设计的特点 函数与类型 Hugs 一个Haskell 解释器,简介,历史背景 什么是函数程序设计 函数程序设计的特色 函数与类型 Hugs 一个Haskell 解释器,软件危机,如何应对计算机程序日益增加的规模和复杂性 (LOC, line of code. Window 3.1(1992) 3million LOC, Windows 2000 30-50million LOC). 如何降低开发软件和维护软件的费用 ( maintenance can be up to 70%, including understanding, debugging and modifying the
3、code) 如何增强我们对于软件正确性的信心(The European Ariane 5(1996), cost 10 years and $7billion, explode after 40s in its maiden voyage; the floating point division in the Pentium processor cost Intel around 470 million ),程序设计语言,一种解决办法是设计一种全新的语言: 编写的程序结构、内容简洁,语义清晰,具有很高的抽象性; 支持软件的重用; 支持快速原型设计; 提供解决问题的工具; 支持和鼓励形式化验证。
4、 函数程序设计语言较好地到达了上述目标。,历史背景,1920s1940s: and Alonzo Church Haskell Currydeveloped lambda calculus(演算), 它是一个函数的理论,也是串行计算的一个模型。,历史背景,1960s:John McCarthydevelops the first functional language Lisp, influenced by lambda calculus, but still with variable assignments.,历史背景,Late 1960s: Peter Landin develops I
5、SWIM, the first pure functional language, based strongly on lambda calculus 1978 John Backus publishes FP, a functional language that emphasized high-order functions and calculating with programs. Mid1970s: Robin Milner develops ML, the first of the modern functional languages, which introduced type
6、 inference and polymorphic types.,历史背景,David Turner develops Miranda 1988: A committee of prominent researchers publishes the first definition of Haskell, a standard lazy functional language. 1999: The committee publishes the definition of Haskell98,Introduction,历史背景 什么是函数程序设计 函数程序设计的特点 函数与类型 Hugs 一
7、个Haskell 解释器,什么是函数程序设计?,C, Java, Ada and Pascal 是命令式( imperative )语言: 一个程序时一些命令的序列,程序运行时命令按顺序执行。关注的焦点: 如何 进行计算. 一个函数程序定义了如何将输入数据转换为输出数据,它是一个表达式:程序的运行通过计算表达式实现。关注焦点: 计算什么. 函数程序设计基于一种不同于其他程序设计语言的程序观:一个程序是从输入到输出的函数,程序的执行是表达式的计算,而非命令的执行。,Let the machine do machines work and let the human do humans work.
8、,什么是函数程序设计 (2),表达式由函数和基本值构成. 例: 计算从1至10 的和.,命令式语言:total = 0;for (I = 1; I=10, I+)total += I;,Haskell语言:sum 110,sum 是一个函数, 110 表示1 至 10的整数.,简介,背景 什么是函数程序设计 函数程序的特点 函数与类型 Hugs 一个Haskell 解释器,函数程序设计的特点,简洁、优美. 函数程序更简洁。例如: qsort.容易理解 qsort = qsort (x:xs) = qsort less + x + qsort morewhere less = y | y = x
9、,函数程序设计的特点(2),无副作用,较少的错误. The result of a function (no side effect) is determined by its input, and only by its input. The result doesnt depend on the evaluation order. This eliminates a whole class of bugs in imperative languages. 强类型. It is impossible to apply a function to a boolean when you shou
10、ld apply it to an int. Bugs are caught at compile-time, rather than run-time. This also makes it less bugy.,Features of functional programming(3),代码重用: Polymorphism enhance reusability. For example, qsort can be used to lists of int, lists of double, lists of any type that has = defined. 模块化: A good
展开阅读全文
