Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this function seem to hide its embedded exception?

While commenting on another question, I discovered an apparent break in referential transparency. In ghci:

> f g h = g `seq` h `seq` \x -> g (h x)
> seq (f undefined id) ()
()
> seq (undefined `seq` id `seq` \x -> undefined (id x)) ()
*** Exception: Prelude.undefined
CallStack (from HasCallStack):
  error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err
  undefined, called at <interactive>:3:14 in interactive:Ghci9

Why isn't the first one bottom? (GHC 8.2.2 in case it matters -- I don't have any other versions installed on this machine at the moment.)

like image 397
Daniel Wagner Avatar asked Jul 13 '18 21:07

Daniel Wagner


People also ask

What is exception in embedded system?

An exception is a synchronous event that occurs during the execution of a thread that disrupts the normal flow of instructions. If exceptions are not properly processed during program execution, severe consequences, such as system failures, can occur.

What is the reason for exception?

11.1 The Causes of Exceptionsevaluation of an expression violates the normal semantics of the language, such as an integer divide by zero, as summarized in §15.6. an error occurs in loading or linking part of the program (§12.2, §12.3) some limitation on a resource is exceeded, such as using too much memory.

What happens if there is no handler for a specific exception?

An exception handler handles a specific class can also handle its subclasses. If no exception handler is found in the call stack, the program terminates.

What happens if an exception is raised in the program and that exception is not handled by an exception section in either the current or enclosing PL SQL blocks?

If an exception is raised in your program and that exception is not handled by an exception section in either the current or enclosing PL/SQL blocks, that exception is "unhandled." PL/SQL returns the error which raised an unhandled exception all the way back to the application environment from which PL/SQL was run.


1 Answers

Looks like this is Trac #14002. If you do a:

> :set -fpedantic-bottoms

or define f in a file and load it into GHCi, then both expressions cause an exception.

The bug report claims it's difficult to fix without incurring a performance penalty.

like image 84
K. A. Buhr Avatar answered Sep 25 '22 03:09

K. A. Buhr