Re:Show HN: Conway's Game of Life in TypeScript's type system
by hbn on Friday September 08, 2023 @05:07PM
(#37439441)
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
[ Parent
| on HN ]
Re:Show HN: Conway's Game of Life in TypeScript's type system
by jimkoen on Friday September 08, 2023 @05:44PM
(#37439773)
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
by chatmasta on Friday September 08, 2023 @05:59PM
(#37439894)
In the case of TypeScript, most of the magic and crazy hacks are dependent on Template Literal Types [0], which is what allows inference based on arbitrary strings. Once you have that abstraction, you can just keep adding complexity to it.
[0] https://www.typescriptlang.org/docs/handbook/2/template-lite...
Re:Show HN: Conway's Game of Life in TypeScript's type system
by prologist on Friday September 08, 2023 @06:02PM
(#37439918)
Any sufficiently advanced type system is indistinguishable from Prolog.
Re:Show HN: Conway's Game of Life in TypeScript's type system
by baq on Friday September 08, 2023 @06:33PM
(#37440157)
Note to readers: if the author’s username doesn’t make it obvious, it’s funny because is true.
If feeling adventurous, read e.g. https://lpn.swi-prolog.org/lpnpage.php?pagetype=html&pageid=...
Re:Show HN: Conway's Game of Life in TypeScript's type system
by divs1210 on Friday September 08, 2023 @07:30PM
(#37440565)
commenting for future reference.
that's a great quote.
Re:Show HN: Conway's Game of Life in TypeScript's type system
by prologist on Friday September 08, 2023 @07:57PM
(#37440792)
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]
Re:Show HN: Conway's Game of Life in TypeScript's type system
by divs1210 on Monday September 11, 2023 @11:48AM
(#37469051)
Yes! I have played with Shen before.
IIRC the type checker is literally a Prolog.
Re:Show HN: Conway's Game of Life in TypeScript's type system
by bazoom42 on Saturday September 09, 2023 @03:13AM
(#37442984)
Typescript has conditional types, which means it can be used as a programming language itself. In theory you can write any arbitrary program - game of life is just an example. You have to define numbers and arithmetics from scratch though, so it is not very practical.
Conditional types are probably rarely used in practial code, but it opens the door for a lot of geekery.
Re:Show HN: Conway's Game of Life in TypeScript's type system
by ushakov on Saturday September 09, 2023 @06:27AM
(#37443854)
We’re using conditional types for type inference in garph (https://garph.dev)