'try' can decide when a program halts

Brrch

I have this function:

isUndefined :: () -> Bool    
isUndefined x = case unsafePerformIO $ (try (return $! x) :: IO (Either SomeException ())) of
                    Left _ -> True
                    Right _ -> False

then:

isUndefined () = False
isUndefined undefined = True

Solving the halting problem. Of course, this can be extended to other types too.

My question: how is this possible? Is Control.Exception.try really breaking things here?

chi

Is Control.Exception.try really breaking things here?

unsafePerformIO is breaking things here. In GHC, undefined simply raises an exception rather than looping forever (which would be unhelpful). Exceptions are not meant to be caught in pure (non-IO) code -- indeed the type system indeed prevents you to attempt as much.

By using unsafe* functions, you are telling GHC "ignore everything, I know what I'm doing", and all the safety belts are now off. Do yourself a favour and pretend that unsafe* stuff does not exist.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Can my thread help the OS decide when to context switch it out?

How can I throw exception inside the try block and terminate the program

Program halts after successive timeout while performing GET request

Program crashes when I try to add contents of a class to on array

Program halts trying to read Excel workbook (Apache POI)

I get stray '#' in program error when I try to compile this program

Node.js halts when console window is scrolled

Program crashes when I try to get the IAudioClient for a channel

MySQL Query crashes my program even when in try statement

Distrubuted PyTorch code halts on multiple nodes when using MPI backend

Mutex lock halts program in mingw but not on linux

Program only throws exception when variable is defined in "try"

Why does my program break when I try to refresh the usestate?

Can anyone tell me why my program crashes when I try to call the Insert or Delete function in a menu driven array manipulation program?

Qt Program freeze when try to get MD5 of files

Program freezes when running as I try to input file contents into listbox

array.length never equals zero and halts the program

View Doesn't Open When I Try To Run My Program?

java try catch when is the program flow interrupted?

Bank Program error when I try to access an account that does not exist

Synaptic wants to remove a lot of packages when I try to upgrade a program

When merging in svn can I decide every change?

Segmentation fault error when I try to run this program

Blocking Task with Event Flags halts the program

When using Robot#mousePress my program halts

Clicking on command window seeming halts program execution, how to prevent this?

.exe program crashes when I try to work with a .txt file

Code in Laravel AppServiceProvider halts Composer & build when deploying via DeployHQ

C++ Program execution halts with no error