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

## 第十二章 The Class of Numbers

1 In the Haskell class of numbers, Int and Integer

a are basically the same type

b are the same type except that numbers of type Integer can be up to 100 digits long

c are different types but x+y is ok, even if x is of type Int and y is of type Integer

d are different types, but both in the Integral subclass

2 In the Haskell class of numbers, Float and Double

a are basically the same type

b are the same type except that numbers of type Double can be up to 100 digits long

c are different types but x+y is ok, even if x is of type Float and y is of type Double

d are different types, but both in the RealFrac subclass

3 What is the most restrictive class containing both the type Integer and the type Float?

a Num

b Real

c RealFrac

d Fractional

4 In the Haskell formula n/d, the numerator and denominator must be in the class

a Integral

b RealFrac

c Fractional

d Floating

5 What is the type of the function f?

HASKELL DEFINITION • f x y = x / y

a Float -> Float –> Float

b Real num => num -> num –> num

c Fractional num => num -> num –> num

d Floating num => num -> num –> num

6 What is the type of the formula ( g n 1) ?

HASKELL DEFINITION • g x y = x + y

HASKELL DEFINITION • n :: Int

HASKELL COMMAND • g n 1

a Int

b Integer

c Integral

d Real

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

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

1 d

2 d

3 b

4 c

(/) :: Fractional a => a -> a –> a

5 c

f :: Fractional a => a -> a –> a

6 a

(+)的类型是：

(+) :: Num a => a -> a –> a

posted @ 2012-12-28 08:42  申龙斌的程序人生  阅读(769)  评论(0编辑  收藏  举报