Revisiting Decimal (generic algorithms)

Brendan Eich brendan at mozilla.com
Fri Jan 16 17:34:31 PST 2009


On Jan 16, 2009, at 5:30 PM, David-Sarah Hopwood wrote:

> David-Sarah Hopwood wrote:
>> function id(x) { return x; }
>>
>> What is the result and type of id(0.1) in this approach, and why?
>
> - if binary 0.1, then we would have
>
>     1m + 0.1 !== 1m + id(0.1)
>
>   which breaks referential transparency (in the absence of side- 
> effects)
>
> - if decimal 0.1m, then we break compatibility with ES3.
>
> - if the value remains generic, then such values must be supported at
>   run-time as a third numeric type besides number and decimal, which
>   seems unsupportably complex to me.

Agreed on all points.

Have you looked at multimethods in Cecil?

http://www.cs.washington.edu/research/projects/cecil/pubs/cecil-oo-mm.html
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.48.8502

Good discussion, let's keep it going.

/be


More information about the Es-discuss mailing list