I copied the Euler.11 solution given on ( http://www.haskell.org/haskellwiki/Euler_problems/11_to_20#Problem_11), but it fails with an indexing error: " (Array.!): undefined array element". Of course firstly I d like a better error message(!), perhaps even giving the failed index, but failing that I tried to debug it.
这些数据是正确的,其印刷版显示了正确的界限和数据。
So I added a few trace messages, to both the result expression, and the body of the comprehension. I get lots of trace results from the final expression, but none from the body computations. Why?
prods :: Array (Int, Int) Int -> [Int]
-- trace ("xs: " ++ show xs) (product xs)
prods a = [trace ("xs: " ++ show xs) (product xs) | i <- range $ bounds a,
s <- senses,
let trace1 = check "i: " i,
let is = take 4 $ iterate s i,
let trace2 = check "is: " is,
all (inArray a) is,
let xs = map (a!) is]
-- Doit
-- euler = print . maximum . prods . input =<< getContents
euler eData = maximum . prods $ input eData
-- Debugging tracecheck :: String -> a -> a
check msg v | trace (msg ++ (show v)) True = v