《Two Dozen Short Lessons in Haskell》学习（十三）迭代及重复的常规模式

第十三章 Iteration and the Common Patterns of Repetition

iterate函数接受2个参数，假设为iterate f x

f x = x + 2

[0, 2, 4, 6, 8, ...]

iterate f 0这个函数有2个参数，第一个参数是f，第二个参数是0

1 The iterate function

a delivers an infinite sequence as its value

b applies a function to the value that function delivers, over and over

c delivers its second argument as the first element of a sequence

d all of the above

2 What value do the following Haskell commands deliver?

a the biggest number that Haskell can compute

b nothing — they aren’t proper commands

c the number that is two more than the starting point

d one delivers the sequence of even numbers, the other the odds

3 Use the iterate function to generate the sequence [x0, x1, x2, x3, …] where x0 = 1 and xn+1 = 11xn mod 127.

a next x = x/127 * 11

iterate next 1

b next x = (11*x) ‘mod‘ 127

iterate next (1/11 ‘div‘ 127)

c next x = (11*x) ‘mod‘ 127

iterate next 1

d none of the above

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

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

1 d

iterate得到一个无限的序列

2 d

[0, 2..]

3 c

posted @ 2013-01-04 22:08  申龙斌的程序人生  阅读(862)  评论(0编辑  收藏  举报