《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

轉載于:https://www.cnblogs.com/speeding/archive/2013/05/01/3015218.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378480.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378480.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378480.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

oracle 查詢不能重復,oracle – 如何防止在選擇查詢中選擇重復行?

我被賦予了從Oracle數據庫中選擇關鍵數據的任務,但我注意到我的select正在返回重復的行.我不需要它們用于我的報告但我不希望它們刪除它們.有人可以幫助只獲取我需要的數據.我嘗試了以下代碼,但這沒有用.SELECT distinct bbp.SUBCAR "Treadwell",bbp.BATCH_ID "…

數字圖像課程工程大作業分析

試題分析: 在連續的視頻中對火焰及水柱的軌跡檢測,效果如圖。 ** 提示: 1、火焰可利用亮度和顏色 2、水柱的軌跡需要先用背景差分獲得水柱的連通域,然后利用連通域上的像素點進行曲線的擬合,水槍的位置視為已知&#…

設計電子商務網站的10個技巧(轉自ITEye)

導讀:隨著先進科學技術的應用,人們無需外出逛幾個小時來“獵”東西,直接坐在家里就可以購買所需商品,支付服務費用。你只需一臺電腦就能搞定。人們習慣了周到的服務和漂亮的櫥窗,對網店的選擇也不例外。因此&#xff0…

分析酸對酸性染料染羊毛染色性能的影響?舉例說明酸性染料染羊毛時,如何選擇合適的染浴pH值?并說明原因。

分析酸對酸性染料染羊毛染色性能的影響?舉例說明酸性染料染羊毛時,如何選擇合適的染浴pH值?并說明原因。 標準答案: 羊毛屬于蛋白質纖維,屬于兩性纖維,酸影響羊毛的解離程度,帶電性及帶電量,影響熱力學性能。等電點以下,羊毛帶正電荷,與陰離子酸性染料之間存在靜電引…

ORACLE連接數據庫(備忘)

常用命令: conn sys/密碼 as sysdba 連接數據庫轉載于:https://www.cnblogs.com/jiangu66/archive/2013/05/01/3053787.html

stl swap函數_vector :: swap()函數以及C ++ STL中的示例

stl swap函數C vector :: swap()函數 (C vector::swap() function) vector::swap() is a library function of "vector" header, it is used to swap the content of the vectors, it is called with a vector and accepts another vector as an argument and swaps…

C++語法:vector的使用

【1】vector的創建與元素插入【2】vector元素的訪問【3】vector的基本使用技巧【4】vector的幾個重要操作【1】vector的創建與元素插入 std::vector<cv::Point> points; //vector容器中保存的類型是Point for (int i 0;i < 10;i) {float x rng.uniform(0, img.cols…

一、經含氟防水劑整理的織物主要存在的不足?

經含氟防水劑整理的織物主要存在的不足? 收集資料階段 含氟防水劑有哪些優缺點 一、含氟防水劑的優點 1、防水效果好,等級高。而無氟防水劑效果相對來說要差一些; 2、兼具防油的功能。無氟防水劑是不具備防油功能的; 3、穩定性好、與其他助劑的配伍好,工藝適應性強;有機…

Apache Web Login Authentication

Apache Web Login Authentication: Adding password protection to a web site using Apache web server authentication. AuthLDAPURL ldap://ldap.your-domain.com:389/ostooges?uid?subAuthLDAPBindDN "cnStoogeAdmin,ostooges"AuthLDAPBindPassword secret1Aut…

oracle中的with的用法,oracle中with子句的用法(轉)

語法&#xff1a;WITH query_name AS (subquery)[, query_name AS (subquery) ]...使用在主select關鍵字前&#xff0c;oracle將其當做一個內聯視圖或者臨時表使用。例子&#xff1a;1.最簡單的使用方法&#xff1a;如查詢部門名稱包含“A”的所有員工信息--with clausewith a …

模擬一個排隊系統

現在有一個數據源&#xff0c;有兩種狀態&#xff08;ON OFF&#xff09;&#xff0c;ON的持續時間服從均值為T_on的指數分布&#xff0c;OFF的持續時間服從均值為T_off的指數分布&#xff0c;源只在ON的時候產生數據包&#xff0c;服從均值為λ的指數分布 模擬一個排隊系統 每…

stl中copy()函數_std :: copy_if()函數以及C ++ STL中的示例

stl中copy()函數C STL std :: copy_if()函數 (C STL std::copy_if() function) copy_if() function is a library function of algorithm header, it is used to copy the elements of a container, it copies the certain elements (which satisfy the given condition) of a…

C++語法:求vector中的最大值及其位置

代碼&#xff1a; #include <iostream> #include <vector> #include <algorithm> using namespace std;int main(){vector<int> a { 2,4,6,7,1,0,8,9,6,3,2 };auto maxPosition max_element(a.begin(), a.end());cout << *maxPosition <&l…

二、織物具備超級防水效果的條件?

織物具備超級防水效果的條件? 收集資料階段 蓮花效應(Lotus Effect),指蓮葉表面具有超疏水(superhydrophobicity)以及自潔(self-cleaning)的特性。 由于蓮葉具有疏水、不吸水的表面,落在葉面上的雨水會因表面張力的作用形成水珠,換言之,水與葉面的接觸角(contacta…

C#編碼簡單性之函數篇(如何編寫簡短的C#代碼,隨時更新)

作者&#xff1a;陳勇出處&#xff1a;blog.csdn.net/cheny_com這是編碼簡單性系列中的其中一篇&#xff0c;之前幾篇包括代碼篇和語義篇。因為要積累案例&#xff0c;會隨時更新。之前提到&#xff1a;編碼簡單性的“心法”就是&#xff1a;只要屏幕上有任何兩部分代碼看上去相…

R學習筆記(1):R是什么

本文最新版已更新至http://thinkinside.tk/2013/05/03/r_notes_1_what.html 在學習量化投資的時候&#xff0c;我發現了R&#xff08;www.r-project.org&#xff09;。R到底是什么呢&#xff1f;在開始之前&#xff0c;先看看R的神奇之處。 1. R初窺 從CRAN&#xff08;The Co…

oracle網卡,Oracle_bond網卡配置

***************************loyu*******************************************************雙網卡創建bond虛擬網卡實驗*************************cat > /etc/sysconfig/network-scripts/ifcfg-bond0 << EofDEVICEbond0BOOTPROTOstaticONBOOTyesIPADDR172.16.116.60N…

Python | 展示一個break語句示例

break is a keyword in python just like another programming language and it is used to break the execution of loop statement. 就像另一種編程語言一樣&#xff0c; break是python中的關鍵字&#xff0c;用于中斷loop語句的執行。 In the given example, loop is runni…

數字圖像處理知識總結

一&#xff1a;基本概念 數字圖像&#xff1a;指由被稱作像素的小塊區域組成的二維矩陣。將物理圖像行列劃分后&#xff0c;每個小塊區域稱為像素&#xff08;pixel&#xff09;。每個像素包括兩個屬性&#xff1a;位置和灰度。圖像數字化一般分為采樣、量化與編碼三個步驟。數…

三、“滌綸纖維和棉纖維兩組分纖維在滌/棉混紡織物燃燒過程中有著明顯的物理相互作用和化學相互作用”,解釋這兩種作用。

“滌綸纖維和棉纖維兩組分纖維在滌/棉混紡織物燃燒過程中有著明顯的物理相互作用和化學相互作用”,解釋這兩種作用。 收集資料階段 棉纖維燃燒后炭化,而滌綸燃燒時熔融滴落,由于棉纖維成為支持體,可使熔融纖維聚集,并阻止其滴落,使熔融纖維燃燒更加劇烈,即所謂"支架效應…