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

  • Home
  • SEARCH
  • 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 6161205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:26:18+00:00 2026-05-23T21:26:18+00:00

I have a problem. I wrote a big Haskell program, and it always works

  • 0

I have a problem. I wrote a big Haskell program, and it always works with small input. Now, when I want to test it and generate a bigger input, I always get the message:

HsProg: Prelude.head: empty list

I use Prelude.head many times. What can I do to find out more or get a better error output to get the code line in which it happens?

  • 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-23T21:26:19+00:00Added an answer on May 23, 2026 at 9:26 pm

    The GHCi option -fbreak-on-exception can be useful. Here’s an example debugging session. First we load our file into GHCi.

    $ ghci Broken.hs
    GHCi, version 7.0.2: http://www.haskell.org/ghc/  :? for help
    Loading package ghc-prim ... linking ... done.
    Loading package integer-gmp ... linking ... done.
    Loading package base ... linking ... done.
    Loading package ffi-1.0 ... linking ... done.
    [1 of 1] Compiling Main             ( Broken.hs, interpreted )
    Ok, modules loaded: Main.
    

    Now, we turn on -fbreak-on-exceptions and trace our expression (main in this case for the whole program).

    *Main> :set -fbreak-on-exception
    *Main> :trace main
    Stopped at <exception thrown>
    _exception :: e = _
    

    We’ve stopped at an exception. Let’s try to look at the code with :list.

    [<exception thrown>] *Main> :list
    Unable to list source for <exception thrown>
    Try :back then :list
    

    Because the exception happened in Prelude.head, we can’t look at the source directly. But as GHCi informs us, we can go :back and try to list what happened before in the trace.

    [<exception thrown>] *Main> :back
    Logged breakpoint at Broken.hs:2:23-42
    _result :: [Integer]
    [-1: Broken.hs:2:23-42] *Main> :list
    1  
    2  main = print $ head $ filter odd [2, 4, 6]
    3  
    

    In the terminal, the offending expression filter odd [2, 4, 6] is highlighted in bold font. So this is the expression that evaluated to the empty list in this case.

    For more information on how to use the GHCi debugger, see the GHC User’s Guide.

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

Sidebar

Related Questions

I have a bit of a problem. I wrote an API a long time
I have problem with return statment >.< I want to store all magazine names
I have learned C++ and Qt4. I wrote one graphical program with 3000 rows
Good day, Stackoverflow! I have a little (big) problem with porting one of my
So I have this reaaaally long method that I want to test. I could
I have to write an applet that brings up a password dialog. The problem
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for

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.