# 《Two Dozen Short Lessons in Haskell》学习（七）- Types

## 第7章 Types

1 The type of [[True, False], [True, True, True], [False]] is

a mostly True

b ambiguous

c [Bool]

d [[Bool]]

2 The type of ["alpha", "beta", "gamma"] is

a [[Char]]

b [String]

c both of the above

d none of the above

3 The type of [["alpha", "beta", "gamma"], ["psi", "omega"]] is

a [[String]]

b [[Char]]

c [String]

d [String, String]

4 The formula foldr1 (.) [f, g, h, k] delivers

a a string

b a function

c a sequence

d nothing — it’s an error because k can’t be a function

5 Which of the following is a sequence whose elements are sequences

a [ "from", "the", "right" ]

b [ [ "Beyond", "Rangoon" ], [ "Belle", "du", "Jour" ] ]

c [ [ 'a' ], [ 'b' ], [ 'c' ] ]

d all of the above

6 The type of the formula foldr1 (.) [f, g, h, k] is

a String -> String

b the same as the type of f

c the same as the type of the composition operator

d [a] -> [b]

7 If the type of f is String -> String, then the type of [f x | x <- xs] is

a String -> String

b String

c [String]

d none of the above

8 The Haskell entity [ [ "Beyond", "Rangoon" ], [ "Belle", "du", "Jour" ] ] has type

a [ [ String ] ]

b [ [ [ Char ] ] ]

c both of the above

d none of the above

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

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

1 d

[[True, False], [True, True, True], [False]] 从最外一层看，是一个List，所以类型应该是[?]，中间是什么类型，需要看每个逗号之间是什么数据。

[True, False]本身也是一个List，类型是[Bool]，同理后面几个也是[Bool]类型

2 c

3 a

[[[Char]]]也正确

4 b

foldr1 (.) [f, g, h, k]把一些函数连接在一起，还是一个函数

5 d

"from"，"the"以及"right"都是Char的列表，这里经常把List称为Sequence

6 b

(.) :: (b -> c) -> (a -> b) -> a –> c

7 c

f类型是String –> String，那么f x就是String类型，[f x | x <- xs]就是[String]

8 c

"Beyond"是String类型

[ "Beyond", "Rangoon" ]是[String]类型

《Two Dozen Short Lessons in Haskell》学习（一）Hello World

《Two Dozen Short Lessons in Haskell》学习（二）Definitions

《Two Dozen Short Lessons in Haskell》学习（四）List Comprehensions

《Two Dozen Short Lessons in Haskell》学习（五）Function Composition and Currying

《Two Dozen Short Lessons in Haskell》学习（六）Patterns of Computation – Composition, Folding, and Mapping

《Two Dozen Short Lessons in Haskell》学习（七）- Types

《Two Dozen Short Lessons in Haskell》学习（八）- Function Types, Classes, and Polymorphism

《Two Dozen Short Lessons in Haskell》学习（九）- Types of Curried Forms and Higher Order Functions

《Two Dozen Short Lessons in Haskell》学习（十）- Private Definitions — the where-clause

《Two Dozen Short Lessons in Haskell》学习（十一）- Tuples

《Two Dozen Short Lessons in Haskell》学习（十二） 数值相关的类

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

《Two Dozen Short Lessons in Haskell》学习（十四）截断序列和惰性求值

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

《Two Dozen Short Lessons in Haskell》学习（十六）- Definitions with Alternatives

《Two Dozen Short Lessons in Haskell》学习（十七） - 模块库

《Two Dozen Short Lessons in Haskell》学习（十八） - 交互式键盘输入和屏幕输出

《Two Dozen Short Lessons in Haskell》学习（十九) - 文件输入与输出

《Two Dozen Short Lessons in Haskell》学习（二十）- 分数

《Two Dozen Short Lessons in Haskell》学习（二十一）- 在形式参数中使用模式匹配

《Two Dozen Short Lessons in Haskell》学习（二十二）- 递归

《Two Dozen Short Lessons in Haskell》（二十四）代数类型

posted @ 2012-11-19 20:05  申龙斌的程序人生  阅读(1232)  评论(1编辑  收藏  举报