当我尝试使用ghci加载我的代码时,它给了我这个错误:
Asig1.hs:4:1:
Non type-variable argument in the constraint: Num [c]
(Use FlexibleContexts to permit this)
When checking that ‘f’ has the inferred type
f :: forall c (t :: * -> *).
(Num c, Num [c], Foldable t) =>
[c] -> [c] -> t [c] -> ([c], [c])
我不明白我做错了什么。 这是我的代码:
module Asig1 where
f as ys x = (s,z)
where
ws = zipWith (*) as ys
s = foldl (+) ws x
z = s
答案 0 :(得分:5)
因为您使用foldl
可能是错误的方法。 input[type=range] {
-webkit-appearance: none; /* Hides the slider so that custom slider can be made */
width: 100%; /* Specific width is required for Firefox. */
background: transparent; /* Otherwise white in Chrome */
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
}
input[type=range]:focus {
outline: none; /* Removes the blue border. You should probably do some kind of focus styling for accessibility reasons though. */
}
input[type=range]::-ms-track {
width: 100%;
cursor: pointer;
/* Hides the slider so custom styles can be added */
background: transparent;
border-color: transparent;
color: transparent;
}
有签名:
foldl
所以你给它一个函数(这里是Foldable t => (b -> a -> b) -> b -> t a -> b
)一个初始值和一系列值。您可以使用以下命令修复代码:
module Asig1 where f as ys x = (s,z) where ws = zipWith (*) as ys s = foldl (+) x ws --instead of foldl (+) ws x z = s
您可以进一步改进代码,因为(+)
不是必需的:
module Asig1 where f as ys x = (s,s) where ws = zipWith (*) as ys s = foldl (+) x ws --instead of foldl (+) ws x