• 《Two Dozen Short Lessons in Haskell》(二十)分数


    《Two Dozen Short Lessons in Haskell》(Copyright © 1995, 1996, 1997 by Rex Page,有人翻译为Haskell二十四学时教程,该书如果不用于赢利,可以任意发布,但需要保留他们的copyright)这本书是学习 Haskell的一套练习册,共有2本,一本是问题,一本是答案,分为24个章节。在这个站点有PDF文件。几年前刚开始学习Haskell的时候,感觉前几章还可以看下去,后面的内容越来越难以理解。现在对函数式编程有了一些了解后,再来看这些题,许多内容变得简单起来了。

    初学Haskell之前一定要记住:

    把你以前学习面向过程的常规的编程语言,如Pascal、C、Fortran等等统统忘在脑后,函数式编程完全是不一样的编程模型,用以前的术语和思维来理解函数式编程里的概念,只会让你困惑和迷茫,会严重地影响你的学习进度。

    这个学习材料内容太多,想把整书全面翻译下来非常困难,只有通过练习题将一些知识点串起来,详细学习Haskell还是先看其它一些入门书籍吧,这本书配套着学学还是不错的。

    第二十章 分数

    1 The Haskell class Fractional includes

    a  integral, real, and complex numbers

    b  numbers between zero and one, but not numbers bigger than one

    c  both floating point and rational numbers

    d  the Mandelbrot set 指的分形图形

     

    2 The mantissa of a floating point number determines 

    a  where the decimal point goes

    b  the range of the number and its sign

    c  the magnitude and precision of the number

    d  the sign of the number and the digits in its decimal numeral

     

    3  The exponent of a floating point number determines

    a where the decimal point goes

    b the range of the number and its sign

    c the magnitude and precision of the number

    d the sign of the number and the digits in its decimal numeral

     

    4  The following denote floating point numbers as the should appear in a Haskell script

    a 1.89533e+25, 18.01528974, 1.05522e-24, +27.0

    b 1.89533 × 1025, 18.01528974, 1.05522 × 10-24, -27.0

    c 1.89533e+25, 18.01528974, 1.05522e-24, -27.0

    d all of the above

     

    5  Analog to digital conversion converts a number

    a  from a set containing a great many numbers to a number from a much smaller set

    b  to zero or one

    c  to a pattern of zeros and ones

    d  by a digital analogy process

     

    6  Which of the following formulas would useful for analog to digital conversion?

    a  floor((x - a)/dx)

    b  floor(n∗(x - a)/(b - a))

    c  floor . (/ dx) . (+(- a))

    d  all of the above

     

    7  Numbers of type Rational in Haskell scripts are

    a  compatible with floating point numbers in arithmetic operations

    b  constructed from two integers by putting a percent-sign between them

    c  especially useful when precision is not the most important factor

    d  all of the above

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

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

    1 c

    书中答案是a,不知道是怎么回事?

     

    2 d

    类型Float和Double的数都包括2个部分:mantissa小数部分,exponent指数部分。

    小数部分决定了该数的正负号和有效数字个数。

    关于详情可以看看IEEE754浮点数表示

     

    3 a

    指数部分决定了小数点的位置。

     

    4 c

    +27.0是错误的表示法,不能把加号放在前面。另外1. 和 .1 也都不是正确的表示法。

     

    5 a

    模数转换就是把范围很大的数转换到一定范围内的数。

    image

     

    6 d

    有点迷惑性,书中的公式对应着答案a。

    答案c是另一种表示法。

    答案b是把dx=(b-a)/n代入a中。

     

    7 b

    Haskell的分数可以用两个整数,在中间放一个百分号来表示。例如:3%5,5%3,-232%365

    直接在ghci中输入上面的表达式会出现Not in scope: `%'错误,需要加载Data.Ratio模块。

    :m Data.Ratio

  • 相关阅读:
    otter安装、使用
    windows下xampp安装rabbitmq的PHP扩展AMQP
    CentOS7下安装RabbitMQ
    CentOS7下开放端口
    CentOS7下安装Redis
    @b.windows.last.use
    Rspec基本语法
    ruby firefox23报错:waiting for evaluate.js load failed
    notepad++上配置ruby执行环境
    cucumber的hooks
  • 原文地址:https://www.cnblogs.com/speeding/p/3015218.html
Copyright © 2020-2023  润新知