3 ms·
The key though is probably to have a strong Number interface, where the overhead of it being an object is complied away, so you can easily switch out different
by jacobr1 3y ago
The key though is probably to have a strong Number interface, where the overhead of it being an object is complied away, so you can easily switch out different implementations, optimize to a more concrete time at AOT/JIT time and have clear semantics for conversion when different parts of the system want different concrete numeric types. You can then have any sort of default you want, such as an arbitrary precision library, or decimal or whatever, but easily change the declaration and get all the benefits, without needing to modify downstream code that respects the interface and doesn't rely on a more specific type (which would be enforced by the type system and thus not silent if incompatible).
- mike_hearn 3y agoThat sort of stuff is easy to do with Truffle (which, ironically, lets you define a language using what they call the "truffle dsl"). The SimpleLanguage tutorial language has a bigint style number scheme with efficient optimization: https://github.com/graalvm/simplelanguage/blob/master/language/src/main/java/com/oracle/truffle/sl/nodes/expression/SLAddNode.java#L64 https://github.com/graalvm/simplelanguage/blob/master/langua...