Re: How to have strongly typed numerical values?

2012-09-06 Thread anonymous
On Thursday, 6 September 2012 at 12:22:08 UTC, David Nadlinger wrote: Can you elaborate on that? I must admit that I didn't actively work on std.units for quite some while now, as general interest in it seemed to have faded (I'm glad to be proven wrong, though), but adding quantities of the sam

Re: How to have strongly typed numerical values?

2012-09-06 Thread David Nadlinger
On Wednesday, 5 September 2012 at 05:53:49 UTC, anonymous wrote: I noticed two flaws in std.units: 1) Can't add quantities of the same type (this is probably trivial to fix). 2) Different scopes don't make different quantity types. Can you elaborate on that? I must admit that I didn't activel

Re: How to have strongly typed numerical values?

2012-09-06 Thread bearophile
Nicholas Londey: however I am less convinced on systems that allow implicit combining of units of the same quantity type. I feel part of the type is its range and precision and so there is no valid way to implicitly add kilometers to millimeters for example. I see. If the range and precision

Re: How to have strongly typed numerical values?

2012-09-06 Thread Nicholas Londey
Thank you everyone for your replies. Initially I think I am going to role my own as my requirements are fairly simple compared to a full blown system with units of measure. My goal is to have large number of application specific types which may be implemented as the same but are semantically

Re: How to have strongly typed numerical values?

2012-09-05 Thread Paul D. Anderson
On Wednesday, 5 September 2012 at 11:50:12 UTC, bearophile wrote: Don Clugston: I'd be interested to know if that idea is ever used in real code. I mean, it's a classic trendy template toy, but does anyone actually use it? As usual I don't have usage statistics. I like dynamic languages, li

Re: How to have strongly typed numerical values?

2012-09-05 Thread bearophile
Don Clugston: I'd be interested to know if that idea is ever used in real code. I mean, it's a classic trendy template toy, but does anyone actually use it? As usual I don't have usage statistics. I like dynamic languages, like Python. But if you give me a static type system, then I want so

Re: How to have strongly typed numerical values?

2012-09-05 Thread Don Clugston
On 05/09/12 03:42, bearophile wrote: Nicholas Londey: for example degrees west and kilograms such that they cannot be accidentally mixed in an expression. Using the static typing to avoid similar bugs is the smart thing to do :-) I'd be interested to know if that idea is ever used in real c

Re: How to have strongly typed numerical values?

2012-09-04 Thread anonymous
On Wednesday, 5 September 2012 at 05:03:38 UTC, Simen Kjaeraas wrote: Not mine, but this is the implementation I use: https://github.com/klickverbot/phobos/tree/units/std Files are units.d and si.d. Documentation: http://klickverbot.at/code/units/std_units.html http://klickverbot.at/code/uni

Re: How to have strongly typed numerical values?

2012-09-04 Thread Simen Kjaeraas
On Wed, 05 Sep 2012 02:55:45 +0200, Nicholas Londey wrote: Hello. I am trying to work out if there is existing support for strongly typed numerical values for example degrees west and kilograms such that they cannot be accidentally mixed in an expression. I have vague recollection of se

Re: How to have strongly typed numerical values?

2012-09-04 Thread Ali Çehreli
On 09/04/2012 08:11 PM, ixid wrote: > Using this: > > struct Grams > { > size_t amount; > } > > @property Grams grams(size_t amount) > { > return Grams(amount); > } > > void main() > { > auto weight = 5.grams; > weight = weight + 10.grams; > } > > How would you use it? I thought the point of this

Re: How to have strongly typed numerical values?

2012-09-04 Thread ixid
Using this: struct Grams { size_t amount; } @property Grams grams(size_t amount) { return Grams(amount); } void main() { auto weight = 5.grams; weight = weight + 10.grams; } How would you use it? I thought the point of this sort of strong typing was to be able to carry out ari

Re: How to have strongly typed numerical values?

2012-09-04 Thread Ali Çehreli
On 09/04/2012 05:55 PM, Nicholas Londey wrote: > I could easily implement my own as I have done in C++ in the > past but assume there is a standard implementation which I would prefer. > Any help or links to examples much appreciated. UFCS enables some interesting syntax: struct Grams { siz

Re: How to have strongly typed numerical values?

2012-09-04 Thread anonymous
On Wednesday, 5 September 2012 at 00:55:12 UTC, Nicholas Londey wrote: Hello. I am trying to work out if there is existing support for strongly typed numerical values for example degrees west and kilograms such that they cannot be accidentally mixed in an expression. I have vague recollection

Re: How to have strongly typed numerical values?

2012-09-04 Thread bearophile
Nicholas Londey: for example degrees west and kilograms such that they cannot be accidentally mixed in an expression. Using the static typing to avoid similar bugs is the smart thing to do :-) I have vague recollection of seeing a presentation by Walter talking about this but I cannot see

How to have strongly typed numerical values?

2012-09-04 Thread Nicholas Londey
Hello. I am trying to work out if there is existing support for strongly typed numerical values for example degrees west and kilograms such that they cannot be accidentally mixed in an expression. I have vague recollection of seeing a presentation by Walter talking about this but I cannot seem