Live data from Hacker News

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

github.com

11–20 of 48 posts

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

#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 computed board into a string literal, looking like:

    const boardstr: PGun10 = `............................................
    ........................xx..................
    ........................x..x................
    ..........x.x...............x......xx.......
    ........x...x..xxx..........x......xx.......
    .xx.....x...................x...............
    .xx....x....x.......xx..x..x................
    ........x.......x.x..x..xx..................
    ........x...x.....xxx.......................
    ..........x.x...............................
    ............................................`;

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

#17
Love it! Reminds me of the hilarious "Typing the technical interview" [1] and "Typescripting the technical interview" [2], a couple of my favorite blog posts of all time.

[0] https://aphyr.com/posts/342-typing-the-technical-interview

[1] https://www.richard-towers.com/2023/03/11/typescripting-the-...

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

#18
post #13

Sometimes I think I don't understand TypeScript's type system and then I see something like this and I realize I know even less than I thought

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.

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

#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

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

#20
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…

I recently had the insight- surely induced by reading something on HN or listening to some podcast- that types are simply functions from the set of all possible "values" to a logical value...
Post reply on HN