ModularM
Modular3y ago
37 replies
gabrieldemarmiesse

In which situation are IntLiteral, FloatLiteral, StringLiteral useful?

I know those refer to the type use by the compiler, and they mean that they are compile time constant.

But it seems to interfer with the alias/var distinction. The constness isn't really clear here.

It seems to me that those type are just compiler implementation details. If we use
alias
and that the compiler cast automatically IntLiteral to Int, FloatLiteral to Float and StringLiteral to String, we don't loose anything (since those can be used in compile-time with
alias
), or am I missing something?

If those types are not useful in the language, should we remove them? In all my programs, I always cast them to the conrresponding runtime types, even if the value is known at compile time.

I guess the more general question is "in which situations is the decorator @nonmaterializable https://docs.modular.com/mojo/manual/decorators/nonmaterializable.html useful?"
Was this page helpful?