`
tangtong
  • 浏览: 64281 次
  • 来自: ...
社区版块
存档分类
最新评论

Section 2.2

阅读更多

2.17

{- Prelude.last                                                                 
-- | Extract the last element of a list, which must be finite and non-empty.    
last                    :: [a] -> a                                             
#ifdef USE_REPORT_PRELUDE                                                       
last [x]                =  x                                                    
last (_:xs)             =  last xs                                              
last []                 =  errorEmptyList "last"                                
#else                                                                           
-- eliminate repeated cases                                                     
last []                     =  errorEmptyList "last"                            
last (x:xs)                 =  last' x xs                                       
  where last' y []     = y                                                      
        last' _ (y:ys) = last' y ys                                             
#endif                                                                          
-}   

-- Because it assure you a nonempty list                                        
lastPair [x] = x                                                                
lastPair (x:xs) = lastPair xs     

 2.18

{- Prelude.reverse                                                              
-- | 'reverse' @xs@ returns the elements of @xs@ in reverse order.              
-- @xs@ must be finite.                                                         
reverse                 :: [a] -> [a]                                           
#ifdef USE_REPORT_PRELUDE                                                       
reverse                 =  foldl (flip (:)) []                                  
#else                                                                           
reverse l =  rev l []                                                           
  where                                                                         
    rev []     a = a                                                            
    rev (x:xs) a = rev xs (x:a)                                                 
#endif                                                                          
-}                                                                              
                                                                                
reverse' [] = []                                                                
reverse' (x:xs) = reverse' xs ++ [x]              

  2.19

cc amount coinValues                                                            
        | amount == 0 = 1                                                       
        | amount < 0 = 0                                                        
        | coinValues == [] = 0                                                  
        | otherwise = (cc amount (tail coinValues)) + (cc (amount - (head coinVa
lues)) coinValues)   

 2.20

不知道怎么定义任意个参数的函数。。

 2.21

squareList = map (\x -> x*x)          

 2.22略

 2.23

forEach = mapM_  

  2.24 ……

  2.25 好像不是很好操作,Haskell里面List不能这么写,Tuple应该用模式匹配。

  2.26 略

  2.27

deepReverse xs = reverse $ map reverse xs                                       

  2.28 concat

  2.29 略

分享到:
评论

相关推荐

    Python核心编程(英文版)

    Section 2.2. Program Input and the raw_input()Built-in Function Section 2.3. Comments Section 2.4. Operators Section 2.5. Variables and Assignment Section 2.6. Numbers Section 2.7. Strings Section 2.8...

    High Performance Python

    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 3.3. Introducing Big O ...

    计算机网络(第四版)(英文版+答案)

    Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The Public Switched Telephone Network Section 2.6. The Mobile ...

    计算机网络英文版(第四版)

    Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The Public Switched Telephone Network Section 2.6. The Mobile ...

    计算机网络 英文原版版(第四版)

    Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The Public Switched Telephone Network Section 2.6. The Mobile Telephone...

    计算机网络第四版(英文原版)

    Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The Public Switched Telephone Network Section 2.6. The Mobile ...

    计算机网络_第四版(andrew S. Tanenbaum)

    Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The Public Switched Telephone Network Section 2.6. The Mobile ...

    网络教程多所重点大学指定教材电子版

    Section 2.2. Guided Transmission Media Section 2.3. Wireless Transmission Section 2.4. Communication Satellites Section 2.5. The Public Switched Telephone Network Section 2.6. The Mobile ...

    apache security 安全

    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 3.2. Configuration ...

    编译原理第二版龙书习题解答(最全_格式已改为手机可查看)

    # Exercises for Section 2.2 ### 2.2.1 Consider the context-free grammar: S -&gt; S S + | S S * | a 1. Show how the string `aa+a*` can be generated by this grammar. 2. Construct a parse tree for this ...

    javascript语言精粹(中英文版)

    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. Objects Section 3.1. ...

    Embedded Linux Primer.pdf

    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 Basics Section 3.1. Stand-...

    Java Network Programming 3rd Edition By Elliotte Rusty Harold 2004

    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 Chapter 3. Basic Web ...

    Web Caching and Replication

    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 Header Section 3.2. ...

    MySql存储过程编程.chm

    Section 2.2. Our First Stored Procedure Section 2.3. Variables Section 2.4. Parameters Section 2.5. Conditional Execution Section 2.6. Loops Section 2.7. Dealing with Errors Section 2.8. ...

Global site tag (gtag.js) - Google Analytics