开发者

Can someone explain this error?

开发者 https://www.devze.com 2023-03-31 19:46 出处:网络
I\'m new to Haskell and struggling with some subtleties of syntax. Why is this fine: reduceBy a f n n < 2 = (a,f)

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

精彩评论

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