Last active
April 4, 2025 15:25
-
-
Save netotz/0f28fd7590a86ea433cede818f0f7eb5 to your computer and use it in GitHub Desktop.
Solving the halting problem using TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type AnyFunction = () => any; | |
/** | |
* Returns true if running `func()` reaches a return statement. | |
* Otherwise, if it loops forever, returns false. | |
* @author God. This function is always right. | |
*/ | |
declare function doesReturn(func: AnyFunction): boolean; | |
function test(): void | never { | |
if (doesReturn(test)) { | |
while (true); | |
} | |
else { | |
return; | |
} | |
} | |
// paradox | |
test(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Link to TypeScript Playground