Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何总结haskell中的奇数索引?_Haskell - Fatal编程技术网

如何总结haskell中的奇数索引?

如何总结haskell中的奇数索引?,haskell,Haskell,奇数项目的数量 定义函数f4,它表示列表中唯一索引的元素之和!索引是例外 f4 :: [Int] -> Int f4 [] == 0 f4 [4] == 4 f4 [4.2] == 4 f4 [4,2,3] == 7 f4 [4,2,3,5] == 7 f4 [5,4,2,3,8,3,9,5,2] == 26 f4 :: [Int] -> Int f4 [] = 0 f4 [x] = x f4 (x:xs) = odd (x:xs) 根据我对控制台输出的理解,此函数可以帮助您:

奇数项目的数量 定义函数f4,它表示列表中唯一索引的元素之和!索引是例外

f4 :: [Int] -> Int
f4 [] == 0
f4 [4] == 4
f4 [4.2] == 4
f4 [4,2,3] == 7
f4 [4,2,3,5] == 7
f4 [5,4,2,3,8,3,9,5,2] == 26

f4 :: [Int] -> Int
f4 [] = 0
f4 [x] = x
f4 (x:xs) = odd (x:xs) 

根据我对控制台输出的理解,此函数可以帮助您:

sumOdds :: [Double] -> Int
sumOdds []  = 0
sumOdds [a] = round a
sumOdds (x:xs) = round x + sumOdds (tail xs)

这个问题我什么都不懂。请编辑它,并尝试更好地解释您的问题。