《Two Dozen Short Lessons in Haskell》学习(十七) - Modules as Libraries

本文提供了一套学习Haskell语言的练习材料,强调了忘记传统面向过程编程的重要性,并介绍了函数式编程的基本理念。通过一系列问题及解答,帮助读者理解模块、加密等概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

《Two Dozen Short Lessons in Haskell》(Copyright © 1995, 1996, 1997 by Rex Page,有人翻译为Haskell二十四学时教程,该书如果不用于赢利,可以任意发布,但需要保留他们的copyright)这本书是学习 Haskell的一套练习册,共有2本,一本是问题,一本是答案,分为24个章节。在这个站点有PDF文件。几年前刚开始学习Haskell的时候,感觉前几章还可以看下去,后面的内容越来越难以理解。现在对函数式编程有了一些了解后,再来看这些题,许多内容变得简单起来了。

初学Haskell之前一定要记住:

把你以前学习面向过程的常规的编程语言,如Pascal、C、Fortran等等统统忘在脑后,函数式编程完全是不一样的编程模型,用以前的术语和思维来理解函数式编程里的概念,只会让你困惑和迷茫,会严重地影响你的学习进度。

这个学习材料内容太多,想把整书全面翻译下来非常困难,只有通过练习题将一些知识点串起来,详细学习Haskell还是先看其它一些入门书籍吧,这本书配套着学学还是不错的。

第17章 模块库

1 Software libraries

a contain functions encapsulated in modules

b provide a way to package reusable software

c both of the above

d none of the above

 

2 A module that supplies reusable software should

a export all of the functions it defines

b import all of the functions it defines

c export reusable functions, but prevent outside access to functions of limited use

d import reusable functions, but avoid exporting them

 

3 The formula concat ["The", "Gold", "Bug"] delivers

a "The Gold Bug"

b ["The", "Gold", "Bug"]

c "TheGoldBug"

d [["The], ["Gold"], ["Bug"]]

 

4 Encryption is a good example to study in a computer science course because

a it is an important use of computers

b it involves the concept of representing information in different ways

c both of the above

d well … really … it’s a pretty dumb thing to study

 

5 The DES cipher is a block cipher. A block cipher is

a a substitution cipher on a large alphabet

b a rotation cipher with scrambled internal cycles

c less secure than a substitution cipher

d more secure than a substitution cipher

 

6 Professor Dijkstra thinks that in the software development profession

a mathematical ability is the only really important asset that programmers need

b the ability to express oneself in a natural language is a great asset to programmers

c mathematical ability doesn’t have much influence on a programmer’s effectiveness

d it’s a waste of time to prove, mathematically, the correctness of program components

=========================================================

=========================================================

1 c

Haskell已经构建了一个庞大的函数库,可以import这些模块来达到重用之目的。

 

2 c

一个模块为了重用,可以让其它模块使用它的函数,但一些内部实现细节不让访问。

以前说过,下面这个模块定义:

module ModuleName (function1, function2)

括号内的函数才对外公开。

 

3 c

concat函数可以把一个列表中的元素连接在一起,定义如下:

concat :: [[a]] -> [a]

concat [[1,2,3], [4,5], [6,7,8,9]]  = [1, 2, 3, 4, 5, 6, 7, 8, 9]

concat的实际内部定义是这样的:

concat = foldr (++) [ ]

就是这个意思:[[1,2,3], [4,5], [6,7,8,9]] = [1,2,3] ++ [4,5] ++ [6,7,8,9] ++ [] = [1, 2, 3, 4, 5, 6, 7, 8, 9]

 

4 c

学习计算机的人们总要接触一些加密方面的知识。

 

5 a

有关DES加密方面的资料,可以参考百度百科

 

6 b

书中关于Dijkstra的原话是:

Besides a mathematical inclination, an exceptionally good mastery of one's native tongue is the most vital asset of a competent programmer.

除了数学爱好,对于一个有能力的程序员来说,出色地掌握自己的母语是最宝贵的财富。

本文转自申龙斌的程序人生博客园博文,原文链接:http://www.cnblogs.com/speeding/archive/2013/03/15/2934519.html,如需转载请自行联系原作者

http://www.cnblogs.com/speeding/ 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值