<div dir="ltr">Hi Karim,<div><br></div><div>I wasn&#39;t aware before how this was supposed to work, but it appears ChucK treats a literal array as an array of the most specific type that encompasses all of its elements. Thats why an array of [SinOsc, SqrOsc, TriOsc] automatically turns into Osc[]. </div><div><br></div><div>On the other hand it is indeed not possible to use an array as an array of its supertype. One reason for this is that x @=&gt; A[0] should work for any UGen x and UGen[] A but would be invalid if A is actually Osc[]. This kind of error would be only detected at run-time and not at compile-time, breaking compile-time type safety. </div><div><br></div><div>In your specific case you could take advantage of the first fact and do something this:</div><div><br></div><div><span style="font-size:12.8px">[s0$UGen, s1, s2] @=&gt; UGen A[];</span><br style="font-size:12.8px"></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">But this doesn&#39;t generalize beyond determining the type of the array when it is defined literally. </span></div><div><br></div><div>spencer</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 4, 2017 at 6:59 AM, Karim Sumun <span dir="ltr">&lt;<a href="mailto:sumun@pobox.com" target="_blank">sumun@pobox.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div><div>Given the following declarations:<br><br></div>SinOsc s0;<br></div>SqrOsc s1;<br></div>TriOsc s2;<br><br></div>The following gives an error:<br><br></div>[s0, s1, s2] @=&gt; UGen A[];<br>$ ... cannot resolve operator &#39;=&gt;&#39; on types &#39;Osc[]&#39; and &#39;UGen[]&#39;...<br><br></div>But the following works fine:<br></div>[s0, s1, s2] @=&gt; Osc A[];<br><br><br></div>It is not a problem, but would like to understand this behaviour. It would seem that assigning to UGen[] would be ok because it looks like a superclass of Osc[].<br><br></div>Aaah! Is this to do with co/contra-variance?<br></div>
<br>______________________________<wbr>_________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.<wbr>princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.<wbr>edu/mailman/listinfo/chuck-<wbr>users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div style="font-family:arial;font-size:small"><div>Spencer Salazar<br></div><div>Doctoral Candidate</div><div>Center for Computer Research in Music and Acoustics</div><div>Stanford University</div><div><br></div><div><a href="mailto:spencer@ccrma.stanford.edu" target="_blank">spencer@ccrma.stanford.edu</a></div><div></div><div>+1 831.277.4654<br></div><div><a href="https://ccrma.stanford.edu/~spencer/" style="color:rgb(17,85,204)" target="_blank">https://ccrma.stanford.edu/~spencer/</a><br></div><div><br></div></div></div></div></div></div></div></div></div></div>
</div>