我试图在haskell中创建一个sum函数.我这样做是为了更熟悉这门语言.我把它定义为:
mysum :: [Integer] -> Integer
mysum lst = sm lst
where
sm :: [Integer] -> Integer
sm lst [] = 0
sm lst [x:xs]=
x + sm xs
Run Code Online (Sandbox Code Playgroud)
我的想法是返回列表头部的值,+尾部反馈到函数中.我记得在F#中做了类似的事情,但我简直无法让它在haskell中工作.
The error im getting is:
sum.hs:5:5: error:
• Couldn't match expected type ‘Integer’
with actual type ‘[[Integer]] -> Integer’
• The equation(s) for ‘sm’ have two arguments,
but its type ‘[Integer] -> Integer’ has only one
In an equation for ‘mysum’:
mysum lst
= sm lst
where
sm :: [Integer] …Run Code Online (Sandbox Code Playgroud) 嗨有一个函数,它接受指针的参数,指向结构的指针.我无法访问我的struct的成员.结构指针的行为与其他类型的指针的行为不同,还是我只是缺少某些必要的东西?
struct mystr {
int num;
};
void fun(mystr **out) {
printf("%d",**out.num); <-- where the problem arises
}
Run Code Online (Sandbox Code Playgroud)