Live data from Hacker News

Show HN: Conway's Game of Life in TypeScript's type system

github.com

31–40 of 48 posts

Re: Show HN: Conway's Game of Life in TypeScript's type system

#31
post #19
post #16

At this point, TypeScript should just let us define types using plain imperative TS code that will execute during static analysis. Might as well. type MyType = someFunc(T) Of course these functions might be typed too…

this is exactly what I want from the Types as Comments proposal[0] as I think it's the only way that types can feasibly become part of the language. It's hard to imagine how all of the concepts TS introduces via special syntax can be covered otherwise. [0] https://tc39.es/proposal-type-annotations

That is a great idea. It also crystalizes the syntax so organisations other than MS can invest in building tooling as the target wont be as fast moving.

Re: Show HN: Conway's Game of Life in TypeScript's type system

#32

Earlier quoted context omitted.

Any sufficiently capable type system will make it possible to implement a form of functional programming. These advanced type systems are essentially a form of pre-compile time scripting to assert certain guarantees about user defined types. It's the same mechanism that makes C++ templates turing complete.

Any sufficiently advanced type system is indistinguishable from Prolog.

commenting for future reference.

that's a great quote.

Re: Show HN: Conway's Game of Life in TypeScript's type system

#34

Earlier quoted context omitted.

Any sufficiently advanced type system is indistinguishable from Prolog.

commenting for future reference. that's a great quote.

Thanks. The Shen language takes this to its logical conclusion (pun intended) and implements a fully Turing complete type system. Types are specified with sequents which are essentially Prolog relations using a slightly different notation.[1]

1: https://shenlanguage.org/OSM/Recursive.html

Re: Show HN: Conway's Game of Life in TypeScript's type system

#35
post #19
post #16

At this point, TypeScript should just let us define types using plain imperative TS code that will execute during static analysis. Might as well. type MyType = someFunc(T) Of course these functions might be typed too…

this is exactly what I want from the Types as Comments proposal[0] as I think it's the only way that types can feasibly become part of the language. It's hard to imagine how all of the concepts TS introduces via special syntax can be covered otherwise. [0] https://tc39.es/proposal-type-annotations

I mean this seems like a nice proposal, but I guess I’m missing something, how does it relate to my comment?

Re: Show HN: Conway's Game of Life in TypeScript's type system

#36
post #15

I'm really confused, is it what TS is supposed to looks like?

It's just a demonstration of how to encode the transition rules for Conway's game of life as a set of types, aka logical constraints. TypeScript's type system has unification, same as in Prolog, and since Prolog is basically Turing complete so is TypeScript's type system.

TypeScripts Type System is Turing Complete #14833

https://github.com/microsoft/TypeScript/issues/14833

Re: Show HN: Conway's Game of Life in TypeScript's type system

#38
post #12

In the typescript playground, the best way to see the output of any evolution number is to have it autocomplete a string literal! Uncomment one of the PGunXX types that you want to see, then below it type this: const boardstr: PGun10 = ``; Then put the cursor inside the two backticks and press Control+Space for intellisense autocomplete, and press enter on the first entry there. Then intellisense will put the compute…

You can also use twoslash[1] caret comments in the playground to display type representations inline, even for uninitialized/declared values, so eg something like this should work:

  declare const boardstr: PGun10
  //            ^?
1: https://www.npmjs.com/package/@typescript/twoslash
Post reply on HN