You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This apparently had performance concerns in early programming languages, but a few languages have implemented it including Swift and Haskell(?).
functionF():uint32{return10;}functionF():string{return"10";}// F(); // TypeError: Ambiguous signature for F. Requires explicit left-hand side type.consta:string=F();// "10"constb:uint32=F();// 10functionG(a:uint32){returna;}G(F());// 10functionH(a:uint8){}functionH(a:string){}// H(F()); // TypeError: Ambiguous signature for F. Requires explicit left-hand side type.
It's possible for an engine to have type inference that supports:
consta=F();G(a);// a must be uint8, thus F():uint8 is the only valid signature.
To what extent should this inference be supported?
Why even support such a complex language feature?
In other languages you'll have people write getString() and getUInt8() or if they support generics get<string>() and get<uint8>(). This seems fine at first glance until you think about operators. Take SIMD operators, represented here by their intrinsic, that can return both a vector register or mask:
__m128i _mm_cmpeq_epi32 (__m128i a, __m128i b)
__mmask8 _mm_cmpeq_epi32_mask (__m128i a, __m128i b)
Notice Intel differentiates signatures by adding _mask. When translated to real types with operators they are identical however:
constsomething=int32x4(0,1,2,3)<int32x4(0,1,3,2);
But if we overload return types we can support both signatures:
This apparently had performance concerns in early programming languages, but a few languages have implemented it including Swift and Haskell(?).
It's possible for an engine to have type inference that supports:
To what extent should this inference be supported?
Why even support such a complex language feature?
In other languages you'll have people write
getString()
andgetUInt8()
or if they support genericsget<string>()
andget<uint8>()
. This seems fine at first glance until you think about operators. Take SIMD operators, represented here by their intrinsic, that can return both a vector register or mask:Notice Intel differentiates signatures by adding
_mask
. When translated to real types with operators they are identical however:But if we overload return types we can support both signatures:
The text was updated successfully, but these errors were encountered: