# 《Two Dozen Short Lessons in Haskell》学习（五）

## 第五章 Function Composition and Currying函数组合与柯里函数

1 Given the following definitions of f and g, the following Haskell command delivers

HASKELL DEFINITION • f str = [ c | c <- str, c == ’x’ ]

HASKELL DEFINITION • g str = [ c | c <- reverse str, c < ’n’ ]

HASKELL COMMAND • f(g "A man, a plan, a canal. Panama!")

a syntax error, unexpected parenthesis

b the empty string

c syntax error, type conflict in operands

d xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

2 Given the above definitions of f and g, and the following definition of teddy, the following command delivers

HASKELL DEFINITION • teddy = "A man, a plan, a canal. Panama!"

HASKELL COMMAND • (f . g) teddy

a syntax error, unexpected parenthesis

b the empty string

c syntax error, type conflict in operands

d xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

3 Given the above definitions of f, g, and teddy, the following Haskell command delivers

HASKELL COMMAND • (f . g) teddy == f(g teddy)

a syntax error, unexpected parenthesis

b the empty string

c True

d xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

4 What would be the answer to the preceding question if, in the definitions of f and g, the sense of all the comparisons

HASKELL DEFINITION • f str = [ c | c <- str, c /= ’x’ ]

HASKELL DEFINITION • g str = [ c | c <- reverse str, c >= ’n’ ]

a syntax error, unexpected parenthesis

b the empty string

c True

d xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

5 If equals is a function that requires two arguments, then equals ’x’ is a function that requires

a no arguments

b one argument

c two arguments

d three arguments

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

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

1 b

g str = [ c | c <- reverse str, c < ’n’ ]把字母n前面的字符都筛选出来，并逆序输出

f str = [ c | c <- str, c == ’x’ ]只输出'x’字符，但很然，前面的小于n的字母里肯定没有x，所以最后的输出结果就是空串[]

2 b

(f . g) teddy等同于f ( g teddy)，与第一题是一个意思

3 c

(f . g) teddy 与 f(g teddy)是等价的，所以(f . g) teddy == f(g teddy)返回True

4 c

5 b