Haskell中的奇怪编译错误

时间:2015-02-11 11:25:47

标签: haskell

为什么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)

1 个答案:

答案 0 :(得分:3)

您的错误在

lastProdAndMax (prod, max) i = (nextProd, max prod nextProd) 
                      ^^^

在该范围内,maxInt(重载max函数)。