您的位置:首页 > 汽车 > 新车 > 卡通图片生成器在线制作_php一键建站_google浏览器入口_企业管理培训公司排行榜

卡通图片生成器在线制作_php一键建站_google浏览器入口_企业管理培训公司排行榜

2024/11/14 13:18:18 来源:https://blog.csdn.net/qq_40514113/article/details/142537175  浏览:    关键词:卡通图片生成器在线制作_php一键建站_google浏览器入口_企业管理培训公司排行榜
卡通图片生成器在线制作_php一键建站_google浏览器入口_企业管理培训公司排行榜

1.What is the most general type of the function

tail
[a] -> [a]

take
Int ->[a] ->[a]

take 3 [True,True,True,True]
[Bool]

take 3
[a]->[a]

(False, ’a’)
(Bool,‘char’)

[(False,0),(True,1)]
[(Bool,char)]

([’a’, ’b’], [False, True])
( [char],[True,True])

twice f x = f (f x)
(a->b)-> a->b

add x y = x * y
Num a =>a->a->a

evens = filter even
Integral a => [a] -> [a] – [Int] -> [Int]

foldr (+) 1 [2,3,4]
10
详解:
foldr (+) 1 [2,3,4]
= 2 + (3 + (4 + 1)) – 从右向左结合
= 2 + (3 + 5)
= 2 + 8
= 10

foldr () 1 [2,3,4]
24
详解:
foldr (
) 1 [2,3,4]
= 2 * (3 * (4 * 1)) – 从右向左结合
= 2 * (3 * 4)
= 2 * 12
= 24

foldr (-) 1 [2,3,4]
2-(3-(4-1) = 2
详解:
foldr (-) 1 [2,3,4]
= 2 - (3 - (4 - 1)) – 从右向左结合
= 2 - (3 - 3)
= 2 - 0
= 2

foldl (-) 1 [2,3,4]
((1 - 2) - 3) - 4 = -8
详解:
foldl (-) 1 [2,3,4]
= ((1 - 2) - 3) - 4 – 从左向右结合
= (-1 - 3) - 4
= -4 - 4
= -8

sum [x | x <- [1…10], even x]
30

zip [1,2] [’a’,’b’,’c’]
[(1,‘a’),(2,‘b’)]

2.What does following expressions evaluate to?
takeWhile even [2,4,6,7,8]
takeWhile函数作用为根据一个条件从列表的开头开始,取出满足该条件的所有元素,直到遇到第一个不满足条件的元素为止。一旦遇到不满足条件的元素,它就停止,并不会继续处–理列表的剩余部分。注意其会停止
[2,4,6,8]

3.Deffne a recursive function

insert :: Int -> [Int] -> [Int]

that inserts an integer into the correct position in a sorted list of
integers.
insert :: Int -> [Int] -> [Int]
insert x [] = [x]
insert x (y:ys) = if x>y then y : insert x ys
else x : y : ys

4.Deffne the following library function using recursion:

and :: [Bool] -> Bool
and [] = True
and (x:xs) = x && and xs

5.Deffne the following library function using recursion:

reverse :: [a] -> [a]
Wrong answer:reverse (x:xs) = reverse xs : x
Correct answer:reverse (x:xs) = reverse xs ++ [x]

6.Deffne the following library function using recursion:

replicate :: Int -> a -> [a]
replicate 0 _ = []
replicate n x = x : replicate (n-1) x

7.Express the sum of the squares of the integers between 1 and 100
using a list comprehension.
sum1 0 = 0
sum1 n= n^2 + sum1(n-1)
OR
sum [ n^2 | n<-[1…100]

8.Express the sum of the products of all pairs of integers between 1
and 100 using a list comprehension.

sum [ x * y | x<- [1…100], y<-[1…100] ]

9.Given the deffnitions

(f . g) x = f (g x)
map f [ ] = [ ]
map f (x:xs) = f x : map f xs

prove the following property of map using induction (for ffnite lists):

map f (map g xs) = map (f . g) xs

见Bilibili视频.

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com