这是《Two Dozen Short Lessons in Haskell》这本书的最后一章,第23章没有习题。

这一章里介绍了Haskell如果自定义一种类型,并且用一个双人博弈游戏为例子讲解了如何使用这些类型,里面简单介绍了Minimax算法。

至此,这本书全部学完,当然还没用Haskell写过什么大一点的程序,只是掌握了其基本概念。

1 A tree, in computer science, is an entity

a with a root and two subtrees

b with a root and a collection of subtrees, each of which is also a tree

c with a collection of subtrees, each of which has one or more roots

d described in a diagram with circles, lines, and random connections

2 A sequence, in Haskell, is an entity

a with one or more elements

b that is empty or has a first element followed by a sequence of elements

c whose elements are also sequences

d with a head and one or more tails

3 The following definition specifies

HASKELL DEFINITION • data WeekDay =

HASKELL DEFINITION • Monday | Tuesday | Wednesday | Thursday | Friday

a a type with five constructors

b a type with five explicit constructors and two implicit ones

c a tree with five roots

d a sequence with five elements

4 Given the definition in the preceding question, what is the type of the following function f?

HASKELL DEFINITION • f Tuesday = "Belgium"

a f :: WeekDay –> String

b f :: Tuesday -> "Belgium"

c f :: Day –> Country

d type of f cannot be determined

5 Types defined in Haskell scripts with the data keyword

a must begin with a capital letter

b may be imported from modules

c must be used consistently in formulas, just like intrinsic types

d all of the above

6 What kind of structure does the following type represent?

HASKELL DEFINITION • data BinaryTree = Branch BinaryTree BinaryTree | Leaf String

a a type with four constructors

b a digital structure

c a tree made up of ones and zeros

d a tree in which each root has either two subtrees or none

7 Given the preceding definition of the type BinaryTree, which of the following defines a function that computes

the total number of Branch constructors in an entity of type BinaryTree?

a branches binaryTree = 2

b branches (Branch left right) = 2

branches (Leaf x) = 0

c branches (Branch left right) = 1 + branches left + branches right

branches (Leaf x) = 0

d branches (Branch left right) = 2*branches left + 2*branches right

branches (Leaf x) = 1

8 The formula xs!!(length xs - 1)

a is recursive

b has the same type as xs

c delivers the same result as last xs

d none of the above

9 Given the definition of the function pam in the module SequenceUtilities, the formula

pam (map (+) [1 . . 5]) 10

a delivers the same result as map (1+) [1 . . 5]

b delivers the same result as pam [1 .. 5] (map (1+))

c delivers the result [11, 12, 13, 14, 15]

d all of the above

10 Given the Grid [1,3,0, 0,0,0, 0,0,2] (as in the tic-tac-toe script), what is the status of the game?

a game over, X wins

b game over, O wins

c O’s turn to play

d X’s turn to play

11 Which of the following formulas extracts the diagonal of a grid (as in the tic-tac-toe program)?

a (take 3 . map head . iterate(drop 4)) grid

b [head grid, head(drop 4 grid), head(drop 8 grid)]

c [head grid, grid!!4, last(grid)]

d all of the above

======

答案

======

1 b

数据结构中“树”的定义,一个根及多个子树

2 b

列表有可能是空的

3 a

data可以来自定义一种类型(也就是面向对象语言中的类),这里有五个构造器constructor。只是这里的构造器都没有带参数。

4 a

这个简单,定义好的类型可以像内置的Haskell类型一样来用。

5 d

类型名称必须是大写字母开头的;可以导入模块中;可以像内置的类型一样用。

6 d

就是二叉树的定义

7 c

求二叉树的分支总数。叶子节点分支为0,否则为左子树的分支数+右子树的分支数。

8 c

!!用来取出一个列表中指定位置上的元素。这里就是取最后一个元素,与last函数一样。

9 c?

还没搞明白pam的意思。

10 c

先走画X,后走的画O。该O方走棋。

130   XX.

000   …

002   ..O

11 b?

答案是b,我认为是d。感觉这些表示方法都正确,答案a中的函数写得相当牛X,不知道为什么不正确?

《Two Dozen Short Lessons in Haskell》(二十四)代数类型的更多相关文章

  1. 《Two Dozen Short Lessons in Haskell》(二十二)递归

    <Two Dozen Short Lessons in Haskell>(Copyright © 1995, 1996, 1997 by Rex Page,有人翻译为Haskell二十四学 ...

  2. 《Two Dozen Short Lessons in Haskell》所有习题的索引

    <Two Dozen Short Lessons in Haskell>(Copyright © 1995, 1996, 1997 by Rex Page,有人翻译为Haskell二十四学 ...

  3. Bootstrap<基础二十四> 缩略图

    Bootstrap 缩略图.大多数站点都需要在网格中布局图像.视频.文本等.Bootstrap 通过缩略图为此提供了一种简便的方式.使用 Bootstrap 创建缩略图的步骤如下: 在图像周围添加带有 ...

  4. 二十四、Struts2中的UI标签

    二十四.Struts2中的UI标签 Struts2中UI标签的优势: 数据回显 页面布局和排版(Freemark),struts2提供了一些常用的排版(主题:xhtml默认 simple ajax) ...

  5. WCF技术剖析之二十四: ServiceDebugBehavior服务行为是如何实现异常的传播的?

    原文:WCF技术剖析之二十四: ServiceDebugBehavior服务行为是如何实现异常的传播的? 服务端只有抛出FaultException异常才能被正常地序列化成Fault消息,并实现向客户 ...

  6. VMware vSphere 服务器虚拟化之二十四 桌面虚拟化之手动池管理物理机

    VMware vSphere 服务器虚拟化之二十四 桌面虚拟化之手动池管理物理机 VMwareView手动池可以管理物理计算机 说明: 环境基于实验二十三 1.准备一台Windows 7的物理计算机名 ...

  7. Bootstrap入门(二十四)data属性

    Bootstrap入门(二十四)data属性 你可以仅仅通过 data 属性 API 就能使用所有的 Bootstrap 插件,无需写一行 JavaScript 代码.这是 Bootstrap 中的一 ...

  8. 3360: [Usaco2004 Jan]算二十四

    3360: [Usaco2004 Jan]算二十四 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 6  Solved: 6[Submit][Statu ...

  9. JAVA之旅(二十四)——I/O流,字符流,FileWriter,IOException,文件续写,FileReader,小练习

    JAVA之旅(二十四)--I/O流,字符流,FileWriter,IOException,文件续写,FileReader,小练习 JAVA之旅林林总总也是写了二十多篇了,我们今天终于是接触到了I/O了 ...

随机推荐

  1. iOSApp上下有黑边

    如图: 这种情况就是没有启动页导致的,加了启动页图片之后就不会再出现了. 设置启动页的方法: http://www.cnblogs.com/BK-12345/p/5218229.html 有的人说我加 ...

  2. Kafka高性能吞吐关键技术分析

    Apache Kafka官网提供的性能说明: Benchmarking Apache Kafka: 2 Million Writes Per Second (On Three Cheap Machin ...

  3. GTX1060 深度学习工具链

    通过试错,推荐GTX1060 WIN10的工具链记录如下: GPU: GTX 1060 6G OS: WIN10 CUDA:9.0 CuDNN:7.1.3 Tensorflow: Tensorflow ...

  4. Notes of Daily Scrum Meeting(12.5)

    最近各种大作业催的比较紧,而且也因为Beta阶段刚刚开始,大家的进展很缓慢,周四因为课业的原因大部分队员 没有做我们的项目,所以就在今天一起总结,我们的问题反馈给学姐之后,学姐也还在看,目前还没有回复 ...

  5. 第二次Scrum meeting

    第二次Scrum meeting 任务及其要求: 成员 12.11 12.12 陈谋 完成Tags的爬取工作(已完成) stackoverflow的问题抽取 卢惠明 视频链接的挖掘和整理(未完成) 视 ...

  6. 基于SSH框架的网上书店系统开发的质量属性

    基于SSH框架的网上书店系统开发的质量属性 对于我的基于SSH框架的网上书店系统的开发要实现的质量属性有可用性.可修改性.性能.安全性.易用性和可测试性. 1.对于可用性方面的战术: 可用性(Avai ...

  7. Jquery封装ajax

    Jquery封装ajax   Load方法     <!-- 将jquery.js导入进来 -->     <script type="text/javascript&qu ...

  8. Leetcode题库——39.组合总和

    @author: ZZQ @software: PyCharm @file: combinationSum.py @time: 2018/11/14 18:23 要求:给定一个无重复元素的数组 can ...

  9. windows 64bit 服务器下安装32位oracle database 11g 问题集

    1.中文乱码 问题描述: 利用vs2008调试的时候正常,发布到IIS8.5上的时候,当查询语句中包含中文的时候会乱码,比如"select * from tb where name='小s' ...

  10. 我们的团队-IT梦想队

    IT梦想队 队长:李遇塘 队员:王长.周兴荣.朱岭杰.马婧婧 团队宣言:  一匹狼战斗力低,但一群狼的我们无所畏惧!李遇塘http://www.cnblogs.com/Liyutang/ 王 长htt ...