4 ms·
// We can also enforce a form of polymorphism with the 'where' clause // This allows the compiler to decide which function to use. // Note: that means that all
by kwhitefoot 11y ago
// We can also enforce a form of polymorphism with the 'where' clause
// This allows the compiler to decide which function to use.
// Note: that means that all information needs to be known at compile-time.
// The param modifier on the arg is used to enforce this constraint.
This sounds like it means that I cannot supply a variable as the argument to whereProc. Is that correct?
- adrusi 11y agoI don't know anything about Chapel beyond what's on this page, but while I'd guess that you're correct, that where clauses only work with constants, given Chapel's widespread use of range types, it's possible that it might be able to prove when numbers are withing a certain range. A lot of languages do this to avoid inserting bounds-checking code to array access where a number can be trivially shown to always be within range. Once you start doing interesting things with numbers though, your ranges start to become to wide to be useful.