Readit News logoReadit News
ycitm commented on TypeScript Native Previews   devblogs.microsoft.com/ty... · Posted by u/simlevesque
ycitm · 3 months ago
Most importantly, this means my type system N-queens solution now works for an 8x8 chessboard (actually up to 10x10) instead of complaining about recursion depth:

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

ycitm commented on AI Avatars Escape the Uncanny Valley   a16z.com/ai-avatars/... · Posted by u/asparagui
ycitm · 5 months ago
Doesn't seem to be any discernable improvement on the Zoom Cat Lawyer.
ycitm commented on TypeScripting the technical interview   richard-towers.com/2023/0... · Posted by u/ycitm
ycitm · 2 years ago
You can also play around with the code in the TypeScript playground:

https://www.typescriptlang.org/play?#code/PTAEEkDsAsEMBsCmAa...

ycitm commented on TypeScripting the technical interview   richard-towers.com/2023/0... · Posted by u/ycitm
jtinder · 2 years ago
An amazing read, and almost perfect!

There's a bug in the Solve "function" due to which you'll get the right answer only for 1x1, 5x5 and 7x7 (I checked till 8x8).

The base case makes a wrong assumption that there will always be a candidate available for the last row. If there are no candidates available, it should return Nil, and backtrack.

Basically, replace

  Concat<candidates, placedQueens>
with

  candidates extends Cons<infer x, any>
    ? Cons<x, placedQueens>
    : Nil

ycitm · 2 years ago
Ah, thank you so much! Great spot.

I've corrected this, and credited you in the errata - https://www.richard-towers.com/2023/03/11/typescripting-the-...

ycitm commented on TypeScripting the technical interview   richard-towers.com/2023/0... · Posted by u/ycitm
davidmurdoch · 2 years ago
I don't really know what it means, but I've seen it used to work around depth issues in Typescript, but can this use a "trampoline"?
ycitm · 2 years ago
I don't think there's any way to do iteration in the type system (other than recursion), so there's no way around it.

I considered forking the compiler to set a deeper limit, but at some point Typescript itself is going to stack overflow. Also that probably goes a bit beyond what Criss is expecting in an interview...

ycitm commented on TypeScripting the technical interview   richard-towers.com/2023/0... · Posted by u/ycitm
Buttons840 · 2 years ago
Why did they only solve for 7 Queens and not 8 Queens?

I'm reminded of https://github.com/type-challenges/type-challenges -- I've only looked at some of the more challenging problems, but one involves writing a JSON parser in the type system. The easy problems look reasonably useful to solve.

ycitm · 2 years ago
I wondered if anyone would spot this :)

There's a recursion depth limit of 500 on the TypeScript compiler, which prevents this solution working for N > 7

Even Aphyr's original Haskell solution only demonstrates N = 6, so in some sense this is an improvement on the state of the art for type-level N Queens solutions /s

ycitm commented on TypeScripting the technical interview   richard-towers.com/2023/0... · Posted by u/ycitm
orf · 2 years ago
Can you link them? I couldn’t find them on his blog.
ycitm · 2 years ago
ycitm commented on TypeScripting the technical interview   richard-towers.com/2023/0... · Posted by u/ycitm
dec0dedab0de · 2 years ago
So he wrote all that for the typescript lsp to respond with the answer, but when it compiles down it's nothing? And we're using runes as variables just because?

That is pretty neat, and silly.

I also think it highlights my natural aversion to static type checking in dynamic languages. I know that I could get sucked into writing a bunch of code for the checker, instead of using my energy for making the application work.

ycitm · 2 years ago
The runes are mostly "just because", but there is a reason.

Ideally, I would have written:

  type Nil = unique symbol
Which would ensure the Nil type wouldn't match with anything but itself. Unfortunately, the compiler doesn't allow unique symbol other than on const variables initialised with Symbol(). So I needed some meaningless symbols.

I could also have done

  type Nil = "nil"
But then it would have looked like the string meant something.

u/ycitm

KarmaCake day492April 5, 2013
About
[ my public key: https://keybase.io/richardtowers; my proof: https://keybase.io/richardtowers/sigs/M-8IG90NBwlLwpscBH7FdJjkNfov9VkYKP9rR6jHYIQ ]
View Original