Mini-Prolog interpreter & ^C
The "readme" file of the mini-Prolog interpreter says: Unfortunately, typing a control C to interrupt a query with an infinite loop will exit the Prolog interpreter completely -- sorry, but I don't know a way around this at the moment. -- A way to implement this, it seems me, is to design Hugs so that a ^C generates a Haskell exception; an unhandled exception should then cause an interrupt. This way, it becomes possible for a program to handle an interrupt without exiting. Hans Aberg
The "readme" file of the mini-Prolog interpreter says: Unfortunately, typing a control C to interrupt a query with an infinite loop will exit the Prolog interpreter completely -- sorry, but I don't know a way around this at the moment.
-- A way to implement this, it seems me, is to design Hugs so that a ^C generates a Haskell exception; an unhandled exception should then cause an interrupt.
The readme you quote is fairly old. GHC provides exactly the kind of exception handling you want. Look for mention of asynchronous exceptions in their documentation and/or read the paper about asynchronous exceptions on Simon Peyton Jones home page. Hugs provides a more limited form of exception handling which lets you catch some exceptions but not others. Unfortunately the mechanism is not well documented, makes it hard to generate good error messages and interacts badly with the recently improved concurrency implementation in Hugs. I don't remember if ctrl-C is on the list of exceptions it can catch. Fixing these deficiencies would be one way of fixing the current problems using the HGL (http://haskell.org/graphics) with the recent Hugs release. It remains to be seen whether I go down that path. -- Alastair Reid
At 14:58 -0700 2001/03/12, Alastair Reid wrote:
The readme you quote is fairly old.
By computer standards, very, very old, something like 1996. Do you remember what did you do in 1996? :-)
GHC provides exactly the kind of exception handling you want. Look for mention of asynchronous exceptions in their documentation and/or read the paper about asynchronous exceptions on Simon Peyton Jones home page.
Yes, I know that Haskell should support exceptions. On the other hand, I may attempt to translate the mini-Prolog Haskell code into C++ for learning purposes, so then I do not need it... :-)
Hugs provides a more limited form of exception handling which lets you catch some exceptions but not others. Unfortunately the mechanism is not well documented, makes it hard to generate good error messages and interacts badly with the recently improved concurrency implementation in Hugs. I don't remember if ctrl-C is on the list of exceptions it can catch.
The reason that I mention it, is that I recall that ^C on Hugs just causes a regular interrupt signal and not an exception. The implementation of ^C as an Haskell exception would probably require first to pick up this signal (as it is usually hardwired to the console), and then rethrow it as a Haskell exception. Then the Hugs evaluation mechanism would take the Haskell program down when it encounters an unhandled exception, mention that it was an interrupt exception that was not handled.
Fixing these deficiencies would be one way of fixing the current problems using the HGL (http://haskell.org/graphics) with the recent Hugs release. It remains to be seen whether I go down that path.
If one writes an entirely new console interface, then one can of course let ^C directly generate a Haskell exception. Hans Aberg
participants (2)
-
Alastair Reid -
Hans Aberg