[swift-evolution] Support for newtype feature/typesafe calculations

Mark Glossop lists at cueballcentral.com
Thu Jan 7 11:40:11 CST 2016


> On 7 Jan 2016, at 23:51, James Campbell via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Yes that is the main purpose. At least 2 of the solutions define protocols which at the very least may be useful to have in the standard library.
> 
> On Thu, Jan 7, 2016 at 3:29 PM, Matthew Johnson <matthew at anandabits.com <mailto:matthew at anandabits.com>> wrote:
> 
>> On Jan 7, 2016, at 9:01 AM, James Campbell via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> Interesting could you upload :) would be good to consolidate all the approaches we have right now so we can come up with the best one:
>> 
>> So far we have:
>> 
>> - Box/Unit Type Protocol (My Solution)
>> - Math Group Protocol (Tino Heth)
>> - Computed typealias (John Randolph)
>> 
> 
> Is the goal of looking at approaches that are possible in the existing language to identify how the language could be improved to better facilitate type safe calculations?  That seems relevant for this list.  But if you get too far into collaborating on solutions you want to use today, that might be a conversation for the swift-users list.

[snip] 

Hi all,

I too have been mulling these ideas over for some time (well before this thread or list started!), but busy yak shaving stuff right now :-/ (hence the list-lurking behaviour...)

In the meantime, I'd suggest looking at the way Mathematica approaches this issue - it's supported units, quantities, multiple standard systems and conversions, and a lot more - and has done so for 20+ years now.

When I free up some time, I plan to see what I can do with Swift lib on this front, but I'd suggest taking a look at Wolfram's "prior work" if this area is of interest to you: https://reference.wolfram.com/language/ref/Quantity.html

There's also this by Martin Fowler on "quantity" types: http://martinfowler.com/eaaDev/quantity.html

Sidebar on decimal numerics since they're relevant to support for currency units - would be nice to know if the "new" IEEE 754 (2008) Decimal floating-point types are in the Swift roadmap?
My suspicion is that any support for them will only come from upstream in LLVM as a first-class type [quad precision/binary128 is supported as the fp128 type; but no decimal floating-point types at present] - so looks like any fixed-point decimal support in the interim would need to be provided by hacking int types, but if anyone wants to chime in... :-)

Cheers,
M.
-- 
Mark Glossop
E: lists <mailto:lists at cueballcentral.com>@cueballcentral.com <mailto:tech at cueballcentral.com>
TW: http://twitter.com/Cueball_AU <http://twitter.com/Cueball_AU>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160108/50fe2e6b/attachment.html>


More information about the swift-evolution mailing list