August 28, 2010 [phobos] std.math.abs + user-defined types | ||||
---|---|---|---|---|
| ||||
std.math.abs looks to have been written to accommodate user-defined numeric types, but then have had pure nothow stuck on it somewhat haphazardly. IMHO now that Phobos is starting to grow some user-defined numeric types, abs() should work with them. Other std library functions should, too, as much as practical. IMHO the best solution for this specific case, since the code is so trivial, is to just make two versions: One that's pure nothrow and accepts builtin numeric types, and one that's not pure nothrow and accepts user-defined types. (Multiplying a BigInt by -1, for example, probably can't easily be made pure.) Should this quick fix be done for now so that abs() works with BigInt and Rational if/when it's checked in? On the other hand, the problem of propagating purity for generic functions probably needs to be addressed on a more general level. I think this is easily solvable and I'm going to propose a solution on the newsgroup momentarily. --Dave |
Copyright © 1999-2021 by the D Language Foundation