# 《Two Dozen Short Lessons in Haskell》学习（十五）- Encapsulation — modules

## 第十五章 封装--模块

1 A Haskell module provides a way to

a share variables and functions between scripts

b hide some of the variables and functions that a script defines

c package collections of variables and functions to be used in other scripts

d all of the above

2 The export list in a module designates variables and functions that

a are defined in the module and redefined in other modules

b are defined in the module and will be accessible to other scripts

c are defined in other scripts and needed in the module

d are defined in other scripts and redefined in the module

3 An import specification in a script

a makes all the definitions in a module available in the script

b designates certain variables and functions in the script to be private

c makes some public definitions from another module available for use in the script

d specifies the importation parameters that apply in the script

4 In a numeric representation scheme based on radix b,

a numbers are denoted by sequences whose elements come from a set of b digits

b numbers are written backwards

c letters cannot be used to represent digits

d numbers larger than b cannot be represented

5 Horner’s formula

a computes the reverse of a sequence of digits

b takes too long to compute when n is bigger than 10

c expresses a sum of multiples of powers of a certain base as a nest of products and sums

d is too complicated to use in ordinary circumstances

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

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

1 d

module ModuleName (function1, function2)

2 b

module DecimalNumerals (integerFromDecimalNumeral, decimalNumeralFromInteger)

where

-- 后面写该模块中的函数定义

3 c

import语句使另外一个模块中的几个函数在当前这段程序中可见，与java语言类似，例如：

import DecimalNumerals (integerFromDecimalNumeral, decimalNumeralFromInteger)

4 a

5 c

horner b ds = foldr (multAdd b) 0 ds

multAdd b d s = d + b*s

posted @ 2013-02-23 10:32  申龙斌的程序人生  阅读(632)  评论(0编辑  收藏  举报