Neat: UFCS for integer dot operator suffix
Philippe Sigaud
philippe.sigaud at gmail.com
Mon Sep 24 06:36:10 PDT 2012
On Mon, Sep 24, 2012 at 2:28 PM, bearophile <bearophileHUGS at lycos.com> wrote:
> monarch_dodra:
>
>
>> I tried this, and found it neat that it works:
I used this in a small unit library (partially accessible on github),
to obtain code like:
auto distance = 100.km;
auto speed = 130.km/h; // division works, too.
auto timeToDestination = (distance/speed).hour; // distance/speed
gives seconds => transformed in hours.
It was a nice exercise in using UFCS and mixins to create your own
unit library (not only IS, but ay kind of unit library).
And, you know what? I *never* used it after coding it. These examples
are cute, they make for nice blog posts for F#, but the real-world
usage is dubious to me (I know they were space-programs crashes)
I quite like the implicit message in units: use the type system to
help you catch errors are compile-time. Add to that a nice syntax and
a showcase for D's generational capabilities and it's quite nice.
But, to my eyes, it's but a toy.
More information about the Digitalmars-d
mailing list