Post #3554193
2026-07-03 09:09 UTC
Language design question: what type should `while True {}` have?
Bottom: It doesn't contain any `break` statements.
Unit: Treat loops with/without `break` consistently.
I already have lints that warn on unreachable code after diverging loops, so the Unit case feels surprising.
Replies (1)
-
@drivel@sueden.social 2026-07-03 10:25
@wilfredh@mastodon.social I had to jump through hoops just this week to satisfy a type checker that didn’t realize that a loop could only be exited via ‚return‘. So bottom appeals to me. I tend to prefer a separate keyword like ‚loop‘ in rust for an infinite loop over special casing ‚while true‘ though. That sets clear expectations that this doesn’t apply for many other ways of spelling ‚true‘.