This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: numeric literals
On 10/26/2011 01:36 PM, Jamison Hope wrote:
On Oct 25, 2011, at 7:15 PM, Per Bothner wrote:
On 10/25/2011 03:45 PM, Jamison Hope wrote:
Is there a simple syntax which will get Kawa to read integral
literals as the appropriate Java SE number types, rather than
the gnu.math types?
I think the place to fix this is in the visitQuoteExp method
in InlineCalls.
...
OK, the attached patch (which touches PrimType.java and InlineCalls.java)
does this. I also put in silent conversions from both IntNum and DFloNum
literals to Float and Double.
I checked this in - thanks!
For non-literals, I think it makes sense to allow explicit
conversions between arbitrary number types, not just IntNum<->BigInteger.
The problem is that Kawa doesn't distinguish explicit and implicit
conversions very well. We need to define when is a conversion "explicit",
and then the compiler needs to take that into account when allowing
(or warning about) conversions. For example explicit conversions might be
initialization and casts, but not function (or method) call or assignment.
Perhaps one could pass in an extra parameter "boolean explicitRequiredType"
in addition to the "Type required" parameter in InlineCalls and related
contexts. Not clear it's worth it at this point. But it would be
worth considering, for example if we add a compiler option to require
strict typing. (Of course such a hypothetical option would be combined
with smart type inference and perhaps a C#-like "dynamic" type.)
--
--Per Bothner
per@bothner.com http://per.bothner.com/