我编写了以下函数:
f :: String -> [(Int, Int)]
f s = zip x y where
x = g s
y = h s
Run Code Online (Sandbox Code Playgroud)
该函数g具有以下签名:
g :: String -> [Int]
Run Code Online (Sandbox Code Playgroud)
和h:
h :: String -> [Int]
Run Code Online (Sandbox Code Playgroud)
我想修改f它以便它返回[(Int, Int, String)],String它的输入在哪里s。我认为这里的问题是 zip 严格适用于两个列表。我怎样才能做到这一点?
我编写了以下简单的程序,对 0 到 9 的数字进行求和:
#include <stdio.h>
#include <stdlib.h>
int* allocArray() {
int arr[10];
return arr;
}
int main(void){
int* p;
int summe = 0;
p = allocArray();
for(int i = 0; i != 10; ++i) {
p[i] = i;
}
for(int i = 0; i != 10; ++i) {
summe += p[i];
}
printf("Sum = %d\n", summe);
}
Run Code Online (Sandbox Code Playgroud)
该代码编译并提供预期结果“45”。但是我收到以下警告:“返回与局部变量‘arr’关联的堆栈内存地址”。我究竟做错了什么?