+1. In fact, typedefs (potentially with associated runtime checking) is
also something I brought up last month in this Dev Core post
<https://groups.google.com/a/dartlang.org/d/msg/core-dev/ZdEBRgxLb70/a-s-iS6JAAAJ>;
As soon as you have that I'm sure you can use it to provide a very well
performing `int` etc.,
Well, we've had consistent, well-understood semantics for Dart for a long
time now, and we still don't have great performance around numbers on all
of the implementations. Still waiting on that Sufficiently Smart Compilerâ¢.
:(
Compiler optimizations are easier to design when given appropriate
developer guidance --- e.g., non-null types help the compiler know when a
developer *intends* a type to be non-null. I think that we have the right
basis for a workable approach: keep the base int type as arbitrary
precision and then let developers provide guidance to the compiler, *as
needed*, via subrange types that are *application specific*: e.g., (let
me just invented some notation)
typedef [1..12] Month;
Most consistent with the current Dart philosophy would be to treat Month
as an int with extra runtime checks in checked mode. A compiler can then do
a much better job at figuring out how to optimally represent a Month.
Cf. Ada which has a base "universal integer" type that effectively
corresponds to the mathematical integers. Every programatic integer type is
a "subtype" of the universal integers (with either standard or modulo
arithmetic).
FYI, examples of Ada range types:
*type* Column *is range* 1 .. 72;
*subtype* Small_Int *is* Integer *range* -10 .. 10;
*subtype* Up_To_K *is* Column *range* 1 .. K;
And examples of (the more expressive Ada 2012 <http://www.ada2012.org>) subtype
predicates feature
<http://www.ada-auth.org/standards/12rat/html/Rat12-2-5.html> (both static
and dynamic variants):
*subtype* Even *is* Integer
*with* Dynamic_Predicate => Even *mod* 2 = 0;
*subtype* Winter *is* Month
*with* Static_Predicate => Winter *in* Dec | Jan | Feb;
In addition to its niche of (safety and security critical) embedded
systems, it seems that Ada is making forays into:
- *IoT*: AdaCore Introduces GNAT GPL 2015 for the Raspberry Pi 2
<http://www.adacore.com/press/adacore-introduces-gnat-gpl-2015-for-the-raspberry-pi-2/>
.
- Space :). Ada running in a CubeSat
<http://www.adacore.com/press/cubesat> (launched in 2013), and a Lunar
IceCube satellite <http://www.adacore.com/press/spark-going-to-the-moon/>
has a planned launch for 2018.
Pretty cool.
Cheers,
Patrice
p.s. For those interested, here <http://www.ada2012.org/comparison.html> is
a compact summary of Ada language features up to and including the Ada 2012
standard.
Perhaps Go-style typedefs would be a useful compromise. Suppose you could
typedef meters num;
typedef seconds num;
Then mixing meters and seconds results in a warning, but they're just
treated as numbers underneath.
typedef int32 int;
This is weird since it doesn't actually put constraints on what's stored
there, but it's good documentation when you're working with foreign types,
and fits in well with Dart's philosophy about type annotations.
Even better would be a way to associate an assertion with each typedef
that's automatically applied to parameters of that type when in checked
mode. That seems pretty consistent with the Dart philosophy too, since it's
just extending how checked mode works anyway.
The goal, then, is to do occasional checks that you're passing and/or
storing values in the right range, not to pervasively change how arithmetic
operations happen.
- Brian
That is why I prefer that basics, including numbers, are implemented by
experts.
I agree totally, it's just that a language team may not *be* the right
experts. We do coincidentally have a couple of people with expertise on
bigints, but as far as I know, we don't have any expertise on using numbers
for financial calculations or dealing with units of measure.
â bob
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.