为什么max prod nextProd
的类型在下面的函数中被推断为Int->Int->Int
而不仅仅是Int?
import qualified Data.Vector as DV
largestProduct::DV.Vector Int->(Int, Int)
largestProduct digits = foldl lastProdAndMax (0,0) [1..((DV.length digits) - 13)] where
lastProdAndMax _ 1 = (first, first) where first = DV.foldl (*) 1 $ DV.take 13 digits
lastProdAndMax (prod, max) i = (nextProd, max prod nextProd)
where nextProd = (prod `div` ((DV.!) digits (i-13))) * ((DV.!) digits i)
答案 0 :(得分:3)
您的错误在
lastProdAndMax (prod, max) i = (nextProd, max prod nextProd)
^^^
在该范围内,max
是Int
(重载max
函数)。