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 8090727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:49:10+00:00 2026-06-05T19:49:10+00:00

In GHCi: Prelude> error (error ) *** Exception: Prelude> (error . error) *** Exception:

  • 0

In GHCi:

Prelude> error (error "")
*** Exception: 
Prelude> (error . error) ""
*** Exception: *** Exception: 

Why isn’t the first one a nested exception?

  • 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-06-05T19:49:11+00:00Added an answer on June 5, 2026 at 7:49 pm

    The answer is that this is the (somewhat surprising) semantics of imprecise exceptions

    When pure code can be shown to evaluate to a set of exceptional values (i.e. the value of error or undefined, and explicitly not the kind of exceptions generated in IO), then the language permits any value of that set to be returned. Exceptional values in Haskell are more like NaN in floating point code, rather than control-flow based exceptions in imperative languages.

    An occasional gotcha for even advanced Haskellers is a case such as:

     case x of
       1 -> error "One"
       _ -> error "Not one"
    

    Since the code evaluates to a set of exceptions, GHC is free to pick one. With optimizations on, you may well find this always evaluates to “Not one”.

    Why do we do this? Because otherwise we’d overly constrain the evaluation order of the language, e.g. we would have to fix a deterministic result for:

     f (error "a") (error "b")
    

    by for example, requiring that it be evaluated left-to-right if error values are present. Very un-Haskelly!

    Since we don’t want to cripple the optimizations that can be done on our code just to support error, the solution is to specify that the result is a non-deterministic choice from the set of exceptional values: imprecise exceptions! In a way, all exceptions are returned, and one is chosen.

    Normally, you don’t care – an exception is an exception – unless you care about the string inside the exception, in which case using error to debug is highly confusing.


    References: A semantics for imprecise exceptions, Simon Peyton Jones, Alastair Reid, Tony Hoare, Simon Marlow, Fergus Henderson. Proc Programming Languages Design and Implementation (PLDI’99), Atlanta. (PDF)

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

Sidebar

Related Questions

The following program yields an error in ghci: {-# LANGUAGE NoImplicitPrelude #-} import Prelude
In GHCI prelude> using :t for finding the types of functions: (.) :: (b
I'm playing around with GHCi for the first time, and I'm having some trouble
In GHCi: Prelude> (+3) 2 5 Prelude> (*3) 2 6 Prelude> (/3) 2 0.6666666666666666
When I :load a Haskell script into GHCi, it changes the prompt from Prelude>
Unfortunately cabal-dev ghci does not work in this project, i get an error: Loading
Look at this output from ghci: Prelude> :t Data.Map.lookup Data.Map.lookup :: Ord k =>
I'm complete newbie on Haskell. My Haskell script with GHCi , Prelude> let a
I've just installed HUnit, and want to import it into ghci. Prelude> import HUnit
So I am doing this in GHCI Prelude> show (5, 6) will get me

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.