6 ms·
In what language are arrays of numbers their own class?
by siika2000 16y ago
In what language are arrays of numbers their own class?
- siika2000 16y agoTo answer my own question: C++ http://www.cplusplus.com/reference/std/valarray/valarray/sum/ http://www.cplusplus.com/reference/std/valarray/valarray/sum...
- sophacles 16y agoIn dynamic languages where arrays can be homogenous, the array can still have a sum method, it just assumes decent coercion rules and overloaded + (or it barfs...).
- IDisposableHero 16y agoThat would be legal in C# 3.5 or later. Though technically it's not that "array of numbers" is a class, but that array of T implements the interface IEnumerable<T>, and Sum() is extension method defined for IEnumerable<int> It's even in the standard libs, you don't have to build it. Documentation is here: http://msdn.microsoft.com/en-us/library/system.linq.enumerable.sum.aspx http://msdn.microsoft.com/en-us/library/system.linq.enumerab...
- IDisposableHero 16y agoIt looks like there's two directions for a language's type system to go: 1) strict typing, but with lots of constructs (e.g. inheritance, interfaces, generics, extension methods) to work around that strictness so that you can do what you want, if you understand the rules and syntax to get it to compile. 2) loose, "duck typing" so you just do what you want, but without compiler checking that it's possible, and with the posibility that it fails at runtime if the right method isn't found. C# is in the first direction.