Initializing an array of bytes

Is there a simpler way to initialize an array of bytes other than casting each element:

private param primegapsize = 22;

private const primegap  : [1..primegapsize] int(8) =
    1:int(8),  1:int(8),  1:int(8),  2:int(8),
    2:int(8),  4:int(8),  2:int(8),  4:int(8),
    2:int(8),  4:int(8),  6:int(8),  2:int(8),
    6:int(8),  4:int(8),  2:int(8),  4:int(8),
    6:int(8),  6:int(8),  2:int(8),  6:int(8),
    4:int(8),  2:int(8)

I really want no run time overhead as by Christmas 2025, I would like to be able to write

private param primegap : [1..primegapsize] int(8) =

If there is not an easy way in existence today, that's cool.


Hi Damian —

Yes, you can move the cast to ': int(8)' outside of the array literal,
which will have the effect of promoting that cast across each of the array
elements, returning a virtual array of int(8)s, like so:

private const primegap = [1, 1, 1, 2, ...]: int(8);

(you can also preserve the explicit type if you prefer; I just dropped it
here for illustration's sake)


Wow. Cool idea. Did I miss that somewhere in the documentation?

Thanks for that detail. I will use that with an array of real(32) sometime.

Wow. Cool idea. Did I miss that somewhere in the documentation?

That's a good question, and I'm not sure. I would not be surprised if
this was not called out explicitly since we view it more as an instance of
promotion than a standalone feature. But we could potentially call it out
in a sidebar in the array literals section of the spec, or could
definitely note it in the arrays primer if it isn't already.