Pineapple 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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
CismonX 1cdaa1698c
Fix bug.
3 months ago
src Fix bug. 3 months ago
.gitignore Add README. 3 months ago
LICENSE Add README. 3 months ago
README.md Add README. 3 months ago
index.ts Implement Pineapple. 3 months ago
package-lock.json Fix bug. 3 months ago
package.json Fix bug. 3 months ago

README.md

README

MIT License

typina - Pineapple interpreter implemented in TypeScript's type system.

Getting Started

Installation:

npm install --save-dev typescript
npm install --save-dev @esolangs/typina

Example usage:

import Pina from '@esolangs/typina';

type Code = `
  $a = "hello"
  $b = " world"
  $a = "goodbye"
  print($a) print($b)
`;
type Output = Pina<Code>;  // Output == 'goodbye world'

Screenshots:

hello world

If you find this interesting... Hey, Pineapple is not even turing complete.

Being Turing complete itself, Typescript's type system is theoretically capable of implementing ANY programming language. See here for an implementation of the Unlambda programming language (which is Turing complete).

Notes

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

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 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.