-
Notifications
You must be signed in to change notification settings - Fork 62
-
Notifications
You must be signed in to change notification settings - Fork 62
Make Float extensible #7348
Comments
If by "extending", you mean "subclassing", that would mean we can't erase the type |
Yes I meant subclassing. An, most likely, ignorant question: Why would it no longer be possible to type erase Float to float? |
Heads up: To achieve the F# feature you describe, it’ll take a lot more
than just subclassing.
…On Sat, Apr 7, 2018 at 7:17 PM loldrup ***@***.***> wrote:
Yes I meant subclassing.
An, most likely, ignorant question: Why would it no longer be possible to
type erase Float to float?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#7348 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABFj24Yyw-HoeFjeElQZ-uaSC-PC8mv7ks5tmUkggaJpZM4TLRJF>
.
|
Because I could assign a value of type |
Right, a proper units-of-measure system is really surprisingly complex. For example, F# lets you write numerical functions that abstract over the unit of measure. |
To make things better, simply embedding a Float in a Length class like shared class Length(shared variable Float val) {} will take about the same amount of memory as a subclass of Float since the compiler can use the primitive type Length len = Length(5);
print(len.val); |
Thanks for the tip!
Kind regardsJon Loldrup
28. Aug 2018 21:07 af notifications@github.com <mailto:notifications@github.com>:
…
To make things better, simply embedding a Float in a Length class like
shared> > class> > Length> (> shared> > variable> > Float> > val> ) {}
will take about the same amount of memory as a subclass of Float since the compiler can use the primitive type > float> to store the value. The downside of course is that you have to refer to the value as:
Length> > len> = > Length> (> 5> );> print> (> len> .> val> );
—
You are receiving this because you modified the open/close state.
Reply to this email directly, > view it on GitHub <#7348 (comment)>> , or > mute the thread <https://github.com/notifications/unsubscribe-auth/AAP_NBOlxYyekupV1CXqVn2HDzttF1tHks5uVZUCgaJpZM4TLRJF>> .
|
If the Float type was extensible, a language user could easily create distinct types for eg. temperatures, distances, weights.
As of current, such values all have to be merely Floats, giving us no type safety against mixing them up when doing computations.
PS. I know that it's possible to define one's own Floaty type, but I also know that it is quite cumbersome. Simply extending Float would give me all that Floatyness for free.
PPS. F# has ability to mingle Floats of various units. Eg. if I divide a value that has a 'lengthy' unit (eg. meters) by a value that has a 'timy unit' (eg. seconds), I get a length per time type. If I multiply a length by a length, I get a 'length squared' type. If I divide a length by a length, I get a scalar value. That's all quite cool. Could Ceylon support something similar, and would that feature be in good harmony with the ability to extend the Float type?
The text was updated successfully, but these errors were encountered: