Unlambda interpreter implemented in TypeScript's type system.
Go to file
CismonX c5e45ff429
Update TypeScript dependency to 4.1 RC.
2020-11-11 14:31:23 +08:00
src prepare for npm 2020-11-06 17:40:02 +08:00
.gitignore initial commit 2020-11-06 17:07:33 +08:00
LICENSE initial commit 2020-11-06 17:07:33 +08:00
README.md Update TypeScript dependency to 4.1 RC. 2020-11-11 14:31:23 +08:00
index.ts prepare for npm 2020-11-06 17:40:02 +08:00
package-lock.json Update TypeScript dependency to 4.1 RC. 2020-11-11 14:31:23 +08:00
package.json Update TypeScript dependency to 4.1 RC. 2020-11-11 14:31:23 +08:00

README.md

README

MIT License

type-unlambda - Unlambda interpreter implemented in TypeScript's type system

Getting Started

Installation:

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

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:

Reverse print string

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. However, TypeScript's type system is not meant for general purpose programming, 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 where 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 to loosen these limits until the error no longer applies. Changing instantiationDepth to 1000 is sufficient to run the example above.