2.1
{-data Ration x = R Integer Integer
instance (Show a) => Show (Ration a) where
showsPrec _ (R n d) = shows (n `div` g).showString " % ". shows (d `div` g)
where g = gcd' n d
gcd' a b = if b==0 then a else gcd' b (a `mod` b)
makeRat a = show a
-}
makeRat x y = (x',y')
where g = gcd x y
s = signum (x*y)
x'= s* abs (x `div` g)
y'= abs (y `div` g)
2.2
makePoint x y = (x,y)
xPoint (x,_) = x
yPoint (_,y) = y
makeSegment (a,b) (c,d) = ((a,b),(c,d))
startSegment ((a,b),_) = (a,b)
endSegment (_,(c,d)) = (c,d)
midpointSegment ((a,b),(c,d)) = ((a+c)/2 ,(b+d)/2)
printPoint (x,y) = do
putStrLn $ show (x,y)
2.3
makeSquare (a,b) (c,d) = ((a,b),(c,d))
getCirm ((a,b),(c,d)) = 2*((abs (c-a)) + (abs (d-b)))
getArea ((a,b),(c,d)) = abs (c-a) * abs (d-b)
2.4~2.5 略
2.6 不太懂,Church 数
one = \f -> \x -> f x
two = \f -> \x -> f (f x)
plus a b = a.b
2-7~2-16 基本都是算法问题,不想做 TODO
分享到:
相关推荐
Section 2.1. Program Output, the print Statement, and "Hello World!" Section 2.2. Program Input and the raw_input()Built-in Function Section 2.3. Comments Section 2.4. Operators Section 2.5. Variables...
Table of Contents | Index ... Preface Who This Book Is For How This Book Is Organized What You Need to Use This Book Conventions Used in This Book ... Section 2.1. Layout Basics
The Theory of Computation, Section 2.1. Introduction, Section 2.2. Problems, Section 2.3. Models of Computation, Chapter 3. Algorithms, Section 3.1. Introduction, Section 3.2. Anatomy of an Algorithm...
Section 2.1. The Theoretical Basis for Data Communication Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The ...
Section 2.1. The Theoretical Basis for Data Communication Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The ...
Section 2.1. The Theoretical Basis for Data Communication Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The Public ...
Section 2.1. The Theoretical Basis for Data Communication Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The ...
Section 2.1. The Theoretical Basis for Data Communication Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The ...
Section 2.1. The Theoretical Basis for Data Communication Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The ...
Section 2.1. The Theoretical Basis for Data Communication Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The ...
Section 2.1. Installation Section 2.2. Configuration and Hardening Section 2.3. Changing Web Server Identity Section 2.4. Putting Apache in Jail Chapter 3. PHP Section 3.1. Installation ...
Section 2.1. Whitespace Section 2.2. Names Section 2.3. Numbers Section 2.4. Strings Section 2.5. Statements Section 2.6. Expressions Section 2.7. Literals Section 2.8. Functions Chapter 3. ...
Section 2.1. Embedded or Not? Section 2.2. Anatomy of an Embedded System Section 2.3. Storage Considerations Section 2.4. Embedded Linux Distributions Section 2.5. Chapter Summary Chapter 3. Processor...
Section 2.1. Networks Section 2.2. The Layers of a Network Section 2.3. IP, TCP, and UDP Section 2.4. The Internet Section 2.5. The Client/Server Model Section 2.6. Internet Standards ...
Section 2.1. Addressing Section 2.2. IP Datagram Header Section 2.3. Routing Section 2.4. Multicast Section 2.5. Summary Chapter 3. Transmission Control Protocol Section 3.1. Segment ...