回 帖 发 新 帖 刷新版面

主题:[讨论]几个关于函数方程编程语言h-a-s-k-e-l-l的问题

Where relevant, provide a small amount of test data for each question, and show results taken from the HUGS system (these can be 
copied and pasted into the document.) Include the test data and output with each question, but comment it out so that the .hs file that 
you hand in can be run. Block comments can inserted between {- and -}. 

1. Redefine the following prelude functions using explicit recursion: 

decide if all logical values in a list are true 

and :: [Bool] -> Bool 

concatenate a list of lists 

concat :: [[a]] -> [a] 

produce a list with n identical elements 

replicate :: Int -> a -> [a] 

3. In the last laboratory you used a list comprehension to define the duplicated function, 
now use recursion (and pattern matching), to define same function 

duplicated :: Eq a => a -> [a] -> Bool 

that takes a list element and a list and returns True iff there is more than one copy of the 
list element in the list. For example: 

duplicated 10 [1,2,11,11] returns False, 
duplicated 10 [1,2,10,11] returns False, 
duplicated 10 [1,2,10,10] returns True. 

4. Using recursion, and your recursive duplicated function, define the function 

nodups :: Eq a => [a] -> Bool 

that takes a list and returns True iff there are no duplicated elements in the list. 
For example: 

nodups [1,2,3,4,5] returns True 
nodups [1,2,2,3,4,4] returns False 


5. Freddie the Frog wants to communicate privately with his girlfriend Francine by encrypting 
messages they send to one another. Frog brains are not large, so they agree on this simple 
strategy: each character in the text shall be encrypted by conversion to the character “one 
greater” than it. 

There are 256 possible characters, which can be associated with the integers 0 to 255. The 
encryption strategy will use wrap-around from 255 to 0, i.e. the character associated with 255, 
when encrypted, will become the character associated with 0. 

Use mapand function composition (.)to define functions encryptand decrypt that 
will allow Freddie and Francine to communicate using their strategy. 

encrypt :: [Char] -> [Char] 
decrypt :: [Char] -> [Char] 

For this problem, you will want to use two built-in Haskell functions, 

toEnum :: Int -> Char and fromEnum :: Char -> Int. 

toEnumwill convert an integer into a character, fromEnumwill convert a character into an 
integer. 

6. Without looking at the definitions from the standard prelude, define the higher-order functions 
all, any, takewhile and dropwhile. 

回复列表 (共2个回复)

沙发

麻烦大家给下答案 救急

跪谢

板凳

C易特元亨QQ919169870
最新互助式项目。
这是一个互助的模式。
不推广人也有钱赚的。分A B两个网。
不推广的人在A网。推广的人 在B网。
B网推广的人帮助A网。
A网赚取6000元出局。
B网就多了。
详情了解加QQ919169870 
  http://blog.sina.com.cn/s/blog_6b19ec920100liv6.html
C易特奖励制度 
http://blog.sina.com.cn/cyite6
C易特更多资料博客

我来回复

您尚未登录,请登录后再回复。点此登录或注册