Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6567535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:20:55+00:00 2026-05-25T14:20:55+00:00

I copied the Euler.11 solution given on ( http://www.haskell.org/haskellwiki/Euler_problems/11_to_20#Problem_11 ), but it fails with

  • 0

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.

The data is input correctly, and a print of it shows the right bounds, and data.

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:20:55+00:00Added an answer on May 25, 2026 at 2:20 pm

    First, making the error message include the failing index would require the Show constraint to be added to the array indices, which may be undesired.

    Second, as Roman said, the messages are not printed because of lazy evaluation. Bang-patterns (let !trace = check "i: " i) may be the most convenient way to circumvent it, but I don’t know exactly how those work inside of list comprehensions.

    Next, the undefined array element message tells you that the array was constructed incorrectly (some elements were left undefined), so you need to debug the function constructing it rather than the function using it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I copied Antlr3.StringTemplate.dll and Antlr3.Runtime.dll from http://www.stringtemplate.org/ to cs-script/lib directory ( http://www.csscript.net/ ) and
this is copied from http://www.zenspider.com/ZSS/Products/RubyInline/Readme.html , the home of rubyinline, adding/moding as indicated in
I've copied and pasted the example ejb-jar.xml and jboss.xml file from http://docs.jboss.org/jbossas/jboss4guide/r4/html/ch6.chapt.html#ch6.mdbejbjar.ex and I'm
I copied the example from http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first and saved it locally to test.html on my
This code is copied directly from http://java.sun.com/docs/books/jni/html/objtypes.html#4013 JNIEXPORT jstring JNICALL Java_Prompt_getLine(JNIEnv *env, jobject obj,
Copied from the site http://github.com/notahat/machinist/ Machinist makes it easy to create test data within
I copied some PHP mailer and at some point had it working. But the
copied following code from http://jqueryui.com/demos/resizable/#default <meta charset=utf-8> <style>#resizable { width: 150px; height: 150px; padding:
I have copied all of the files for the Google example http://gmaps-samples-v3.googlecode.com/svn/trunk/toomanymarkers/toomanymarkers.html to my
I copied clang_complete.vim to plugin, but when I typed . after some variable, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.