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.
精彩评论