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
Show HN: Conway's Game of Life in TypeScript's type system
31–40 of 48 posts
Re: Show HN: Conway's Game of Life in TypeScript's type system
#32Earlier 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.
that's a great quote.
Re: Show HN: Conway's Game of Life in TypeScript's type system
#33Re: Show HN: Conway's Game of Life in TypeScript's type system
#34Earlier quoted context omitted.
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
#35At 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
Re: Show HN: Conway's Game of Life in TypeScript's type system
#36I'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.
Re: Show HN: Conway's Game of Life in TypeScript's type system
#37Ha! More performant than I'd have guessed. I tried commenting `PrintBoard >` in and out and it took about 3 seconds (in the ts playground).
Re: Show HN: Conway's Game of Life in TypeScript's type system
#38In 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…
declare const boardstr: PGun10
// ^?
1: https://www.npmjs.com/package/@typescript/twoslash