Add shorthand for casting integer types #173
Labels
good first issue
An issue that doesn't require deep knowledge of the compiler to fix or implement
language feature
A feature proposal for something added to the core language (not the standard library)
Currently to cast a value to an integer type one needs to use the
cast
function and often a type hint as well. This can be somewhat awkward both to read and write:Ante should support a shorthand for casting to primitive integer types at least - and potentially all primitive types. This shorthand can be similar to constructor syntax for user-defined types:
Since the various primitive types tend to be short, this is almost always shorter than the
cast
approach while making the intent of casting to aUsz
(in this case) more clear.Proposed implementation strategy
t x
it will desugar tocast x : t
instead.Open questions:
U8 x
immediately, perhapsU8
when used in an expression position should be a valid identifier. This way, users couldd passU8
as a function to higher order functions such asmap
to cast each element of a container. The prelude could also then define the cast functions for each integer type trivially:U8 x = cast x : U8
. A downside of this approach is that new users may be confused on the two different meanings of these types when used in a type position or an expression position. If Ante ever gets fully dependent types, this would conflict with that as well since types and values would need to live in the same namespace.The text was updated successfully, but these errors were encountered: