《Two Dozen Short Lessons in Haskell》学习(十七) - Modules as Libraries
《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.
除了数学爱好,对于一个有能力的程序员来说,出色地掌握自己的母语是最宝贵的财富。
----==== Email: slofslb (GTD) qq.com 请将(GTD)换成@ ====----
版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)
作者:申龙斌的程序人生
---- 魔方、桥牌、象棋、游戏人生...
---- BASIC、C++、JAVA、C#、Haskell、Objective-C、Open Inventor、程序人生...
---- GTD伴我实现人生目标
---- 区块链生存训练
---- 用欧拉计划学Rust编程
---- 申龙斌的读书笔记(2011-2019)
----

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构