Skip to content

Instantly share code, notes, and snippets.

@netotz
Last active November 10, 2022 17:59
Show Gist options
  • Save netotz/0f28fd7590a86ea433cede818f0f7eb5 to your computer and use it in GitHub Desktop.
Save netotz/0f28fd7590a86ea433cede818f0f7eb5 to your computer and use it in GitHub Desktop.
Solving the halting problem using TypeScript
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();
@netotz
Copy link
Author

netotz commented Nov 9, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment