I really like todo keyword.
Especially if it will be possible to make this warning into error in CI build only.
So I will be able to run & debug unfinished work locally, but have guarantee that it won't get into master branch.
I don't get why it has to be a keyword. It can be a function with return type bottom.
In Rust it's a macro, but not for type checking. The reason is only that it can take an optional format string, and arguments, and functions can't have optional/vararg parameters (and also, format strings are statically compiled), a more dynamic language wouldn't have that problem.
The history on Rust’s todo!() is fun, because that’s actually not the reason why it was first made a macro.
First there was fn std::util::unreachable(). You had to import it, and the panic source printed out was …/rust/src/libstd/util.rs:132, which wasn’t very useful.
I wasn’t happy with this, and so proposed turning into a macro <https://github.com/rust-lang/rust/issues/8991>, which fixed both of those problems. The import thing alone could have been resolved by adding it to the prelude, but the panic message file/line thing couldn’t be fixed at the time other than by turning it into a macro.
At some point (still before 1.0.0) unimplemented!() was added as “unreachable!() but with a different message”.
In 1.20.0, these macros got the ability to take format arguments, because why not, since they’re already macros anyway, and adding an extra message is sometimes quite helpful. <https://github.com/rust-lang/rust/pull/42155>
Until this change, the sole reason for them being macros was the file and line number thing.
Then from October 2019 (though not stabilised until 1.46.0, but the standard library could immediately use it) came the really amusing part: this original reason became obsolete with #[track_caller].
So really there have been three distinct answers to “why is it a macro?” for three phases of Rust’s life:
• Before 1.20.0: “so the panic output gets the right file and line number”.
• Between 1.20.0 and 1.forty-something: “so the panic output gets the right file and line number, and because it takes format args”.
• Since then: “because we didn’t have #[track_caller] before 1.0.0 (since changing it from a macro to a function now would be a breaking change), and more recently because it accepts format args”.
If we’d had #[track_caller] back in 2013 (or any plans in that direction), we wouldn’t have made unreachable a macro, and then unimplemented would have also been made a function, and then format args stuff couldn’t have been added without introducing new macros, and I’m dubious it’d have happened.
Little things in history and how they affect the future can be fascinating to observe. This is a tiny and pretty harmless point, which I largely remember because it was one of my early contributions (and I haven’t made a large number in total, to drown it in volume), but there are many other things in Rust where little pragmatic decisions long ago have been causing all sorts of pain in trying to properly generalise them now. Const generics is far from the worst, but perhaps the simplest to observe, especially in how things have largely eventually been fixed (whereas various others have just ended up dead in the water). The [T; 0], [T; 1], [T; 2], …, [T; 12] implementations and similar have caused quite a lot of trouble.
(todo!() was added in 1.40.0 as a third member of this family of “panic!() but with a different message and intended semantics” macros.)
Gleam has no subtyping so it has no bottom type, but you could still make a function that returns an unbound type variable.
However there's no advantage of implementing this in user-land. Having it be part of the language means the compiler can do things like emit a warning when it is used, ban it in release builds, and so on.
This isn't totally unusual. In language like Haskell you can put something with a maximally general type (a "bottom", e.g. `undefined`) in as a placeholder anywhere in the program and your compile will go through. If you want to get even fancier you can put a "typed hole" that says something like "I don't know exactly what this is yet, but it's definitely going to return a list of ints".