On 3/24/13 1:09 AM, Patrick Walton wrote:
I'd like to use the colon for type ascription (i.e. an *assertion* that a value has some type), which is different from a cast. This would be useful to help along the typechecker in cases in which it doesn't have enough information to determine the result of an expression. For example:
I see that Scala uses the colon for type ascription like you describe, so you have precedent on your side. :)

http://docs.scala-lang.org/style/types.html#ascription

Similar syntax is OCaml's :> for (static) upcasts and :?> for (dynamic) downcasts. That's not helpful for casting types that don't have a subtype relationship, such as u8 and u16 in my example earlier. However, rust's integral types could be special-cased such that:

   let big = 0x54321;
   let a = big :> u16; // big & 0xffff truncated like C
   let b = big :?> u16; // fail! runtime error because big is out of range


chris

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to