Skip to content

susisu/lambda2ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lambda2ts

A PoC compiler that translates untyped lambda calculus into TypeScript types.

Background

Recently, a new technique has been discovered that enables the use of first-class type-level functions in TypeScript (see gvergnaud/hotscript). For example, we can write and use first-class type-level functions as follows:

// Fun is the interface that represents first-class type-level functions.
interface Fun {
  arg: unknown;
  ret: unknown;
}

// App<F, X> applies a function F to an argument X.
type App<F, X> = F extends Fun ? (F & { arg: X })["ret"] : never;

// Functions are defined by extending the Fun interface.
// The argument can be accessed via this["arg"].
interface IsNumber extends Fun {
  ret: this["arg"] extends number ? true : false;
}

// Apply functions using App<F, X>.
// Functions can also be composed using high-order functions.
type FilterSet<F, X> = X extends unknown ? (App<F, X> extends true ? T : never) : never;
type MyType = FilterSet<IsNumber, "foo" | 42 | true | null | 0 | undefined>; // = 42 | 0

This idea enables us to compile untyped lambda calculus to TypeScript types more directly than before. Therefore, I have developed a PoC compiler.

Demo

License

MIT License

Author

Susisu (GitHub, Twitter)

About

A PoC compiler that translates untyped lambda calculus into TypeScript types

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages