简体   繁体   English

有人可以解释这个错误吗?

[英]Can someone explain this error?

I'm new to Haskell and struggling with some subtleties of syntax. 我是Haskell的新手,并且在语法上有些微妙。 Why is this fine: 为什么这样很好:

reduceBy a f n
    | n < 2 = (a,f)
    | (a `mod` n) == 0 = 
        reduceBy( floor $ fromIntegral a / fromIntegral n) (f++[n]) n
    | otherwise = (a, f)

While this has errors: (Couldn't match expected type `(a, [a])' against inferred type `[a] -> a -> (a, [a])' ) 虽然这有错误:(无法将预期的类型`(a,[a])与推断的类型`[a]-> a->(a,[a])'匹配起来)

reduceBy a f n
    | n < 2 = (a,f)    
    | (a `mod` n) == 0 = 
        reduceBy( floor(fromIntegral a / fromIntegral n) (f++[n]) n )    
    | otherwise = (a, f)

?

Your new closing parenthesis comes too late. 您新的右括号来不及了。 It should be 它应该是

... reduceBy (floor(fromIntegral a / fromIntegral n)) ...

The $ binds fairly weakly, but parentheses trump everything. $绑定力很弱,但是括号胜过一切。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM