Nim's type cast syntax is sometimes looking annoying. Here is a syntactic sugar I used recently.
proc `[]`*[T](x: T, U: typedesc): U = cast[U](x)
var i = 1
echo cast[float](i)
echo i[float]
echo cast[int](i.addr)
echo i.addr[int]
Looking like seq[int], clear and easy. Type casts are a crude mechanism to interpret the bit pattern of an expression as if it would be of another type. Type casts are only needed for low-level programming and are inherently unsafe.
It is much more likely that someone would want to use a conversion, like float(1234).
If you do need to interpret the same bits as a different type (for which there are indeed valid use cases), I would argue that it's much better to be explicit about this. I also think that the slightly ugly syntax matches the fact that the whole idea of what's happening here is slightly ugly in itself.
Of course, your own projects are your own business, but it would be my recommendation to avoid creating weird constructs like this. It makes it harder to read for the next person who comes along trying to learn your code. I would especially advise against it if you're doing something open source.
I don't like it for similar reasons to @ncrosby but more importantly because it makes it impossible for users to tell which is a cast and which is an generic without looking at all imported symbols:
import typetraits
import foo # defines `type = myseq[T]` or `var myseq: float`
echo myseq[int] # could mean echo cast[int](myseq) or echo myseq[int].name, depending
however, what I would like is UFCS cast:
12.cast(float)
which currently doesn't compile, but which has much better syntax than cast, while still remaining distinctive and grepableif obj of Child:
let child = cast[Child](obj)
In this case, I think use obj[Child] is more clear. However, this is just my opinion, any one can decide use it or not.
You may read again the manual section ncrosby cited, or read tutorial:
https://nim-lang.org/docs/tut2.html#object-oriented-programming-type-conversions
In Nim we generally avoid casts, but we may do type conversion:
if obj of Child:
let child = Child(obj)