4 ms·
Interesting point. Getting the type annotation inferred for you there is definitely useful. I've used it a few times myself. The `undefined` trick is also imme
by burntsushi 12y ago
Interesting point. Getting the type annotation inferred for you there is definitely useful. I've used it a few times myself.
The `undefined` trick is also immensely useful. I use it a lot when starting a new module. Rust also has a notion of bottom, indicated by `!`, which will unify with all types. I frequently use this in Rust in a similar way that I use `undefined` in Haskell. (In Rust, you would speak `fail!()` or `unreachable!()` or `unimplemented!()` or define-your-own.)
> (if you've ever written a little wrapper around a function from a complicated library, you know what I mean)
Yes, absolutely. I haven't really run into this problem with Rust yet though. Types are generally pretty simple. If and when Rust gets higher-kinded types, that would assuredly change.
- fanf2 12y agoI thought ! in Rust indicates a macro.
- burntsushi 12y agoA `!` followed by an identifier does, yes. But a `!` also lets you define diverging functions: fn diverging() -> ! { unreachable!() } The two `!` in that code are completely orthogonal things. See the manual on diverging functions: http://doc.rust-lang.org/rust.html#diverging-functions http://doc.rust-lang.org/rust.html#diverging-functions