Unlambda interpreter implemented in TypeScript's type system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
CismonX ecbdb92fe9
Update README.
4 months ago
assets Store screenshots in git repo. 4 months ago
src Wrap lines to 79 characters max. 5 months ago
.gitignore initial commit 12 months ago
LICENSE Update license year. 5 months ago
README.md Update README. 4 months ago
package-lock.json Update README. 4 months ago
package.json Update version. 5 months ago

README.md

type-unlambda

MIT License

Unlambda interpreter implemented in TypeScript's type system.

Getting Started

Installation:

npm install --save-dev typescript
npm install --save-dev @esolangs/type-unlambda

Example usage:

import Unlambda from '@esolangs/type-unlambda';

type Code = '``@c`d``s`|k`@c';
type Input = 'Hello!';
type Output = Unlambda<Code, Input>;  // Output == '!olleH'

Screenshots (from Visual Studio Code):

Example

Notes

You're likely to get the following error when trying to run a program with type-unlambda:

Type instantiation is excessively deep and possibly infinite.ts(2589).

To write loops in TypeScript's type system, we have to use recursions, like we do in other purely functional programming languages. Meanwhile, we use CPS to implement continuations, which also introduces heavy recursion.

However, TypeScript's type system is not meant for general purpose programming. There is no TCE, and recursion has its limits.

In src/compiler/checker.ts, there is a hard-coded limit for type instantiation:

if (instantiationDepth === 50 || instantiationCount >= 5000000) {
    // ...
    return errorType;
}

You may expect that there is an option somewhere that this limit can be configured, like -ftemplate-depth=n in gcc/clang. Unfortunately, there isn't, and it's likely to stay that way.

To workaround this limitation, we modify the code of tsserver or tsc in node_modules, until the error no longer applies. Changing instantiationDepth to 1000 is sufficient to run the example above.