以下代码意在产生双倍或整数。 s
被假定为 negate
或
;
整个部分;以及 的整数部分或
nothing
。
computeValue :: Num a => (a->a) -> Integer -> (Maybe Double) -> Either Double Integer
computeValue s n Nothing = Right $ s n
computeValue s n (Just a) = Left $ s (fromIntegral n + a)
当我整理这个时,我得到的是:
test1.hs:2:28:
Couldn t match type `Integer with `Double
Expected type: Either Double Integer
Actual type: Either Double a
In the expression: Right $ s n
In an equation for `computeValue :
computeValue s n Nothing = Right $ s n
test1.hs:2:38:
Couldn t match type `Integer with `Double
In the first argument of `s , namely `n
In the second argument of `($) , namely `s n
In the expression: Right $ s n
编译者似乎不知何故失去了对 s
是多元形态这一事实的了解。 这里发生了什么, 以及我如何修正它?