小编J. *_*dge的帖子

Haskell - zip 替代品

我编写了以下函数:

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 严格适用于两个列表。我怎样才能做到这一点?

haskell

2
推荐指数
1
解决办法
180
查看次数

C - 避免警告“与返回的局部变量关联的堆栈内存的地址”

我编写了以下简单的程序,对 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’关联的堆栈内存地址”。我究竟做错了什么?

c arrays pointers

2
推荐指数
1
解决办法
2790
查看次数

标签 统计

arrays ×1

c ×1

haskell ×1

pointers ×1