我完全失去了爲什麼下面不工作:爲什麼(字符串,詮釋)預期而不是(字符,詮釋)?
takeRange :: Int -> (a,Int) -> [(a,Int)] -> [(a,Int)]
takeRange n elem list = dropWhile (\x -> snd x < snd elem) (takeWhile (\x -> snd x < (snd elem) + n) list)
seriesLargestProd :: String -> Int -> Int
seriesLargestProd "" _ = 0
seriesLargestProd _ 0 = 0
seriesLargestProd s n = maximum [foldl1 (*) $ map (read . fst) (takeRange n pair zipped)
| pair <- zipped, snd pair <= lastStartingIndex]
where zipped = zip s [1..]
lastStartingIndex = (length s) - (n-1)
錯誤消息我得到:
Couldn't match type `Char' with `[Char]' Expected type: (String, Int) Actual type: (Char, Int) In the second argument of `takeRange', namely `pair' In the second argument of `map', namely `(takeRange n pair zipped)' Couldn't match type `Char' with `[Char]' Expected type: [(String, Int)] Actual type: [(Char, Int)] In the third argument of `takeRange', namely `zipped' In the second argument of `map', namely `(takeRange n pair zipped)'
如果任何人的興趣,這應該是一個答案問題8的Project Euler。
謝謝你的回答。這真的很有幫助。 – Kapol