0
爲什麼max prod nextProd
的類型在下面的函數中被推斷爲Int->Int->Int
而不僅僅是Int?Haskell中的奇怪編譯錯誤
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)
arghhh ...我一定會變得失明:[|]謝謝! – Julio 2015-02-11 11:30:10
@Julio使用'-Wall' GHC標誌會觸發全局'max'的陰影警告,指出問題所在。 – chi 2015-02-11 11:59:17