开发者

Can someone explain this error?

I'm new to Haskell and struggling with some subtleties of syntax. 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])' )

reduceBy a f n
    | n < 2 = (a,f)    
    | (a `mod` n) == 0 = 
        reduceBy( floor(fromIntegral a / fromIntegral n) (f++[n]) n )    
开发者_如何学Go    | 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜