Related articles |
---|
My scripting language - any suggestions? licaner@gmail.com (lican) (2008-08-25) |
Re: My scripting language - any suggestions? jaluber@gmail.com (Johannes) (2008-08-27) |
Re: My scripting language - any suggestions? lerno@dragonascendant.com (=?ISO-8859-1?Q?Christoffer_Lern=F6?=) (2008-08-27) |
Re: My scripting language - any suggestions? licaner@gmail.com (lican) (2008-08-29) |
Re: My scripting language - any suggestions? jaluber@gmail.com (Johannes) (2008-08-30) |
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-08-31) |
Re: My scripting language - any suggestions? ademakov@gmail.com (Aleksey Demakov) (2008-08-31) |
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-08-31) |
Re: My scripting language - any suggestions? licaner@gmail.com (lican) (2008-08-31) |
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-09-01) |
Re: My scripting language - any suggestions? ademakov@gmail.com (Aleksey Demakov) (2008-09-02) |
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-09-02) |
Re: My scripting language - any suggestions? licaner@gmail.com (lican) (2008-09-04) |
Re: My scripting language - any suggestions? jaluber@gmail.com (Johannes) (2008-09-06) |
[5 later articles] |
From: | "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> |
Newsgroups: | comp.compilers |
Date: | Sun, 31 Aug 2008 16:58:20 +0200 |
Organization: | cbb software GmbH |
References: | 08-08-069 08-08-081 08-08-100 08-08-106 08-08-107 |
Keywords: | types |
Posted-Date: | 31 Aug 2008 11:17:17 EDT |
On Sun, 31 Aug 2008 21:04:15 +0700, Aleksey Demakov wrote:
> On Sun, Aug 31, 2008 at 4:26 PM, Dmitry A. Kazakov
> <mailbox@dmitry-kazakov.de> wrote:
>> In a language with an elaborated types system Integer and Float would have
>> subtyping relation making explicit conversions unnecessary, for instance
>> when Integer were a subtype of Float, then it could inherit contravariant
>> Floor from Float:
>>
>> Floor : Integer -> Float (contravariant in the result)
>
> If Integer is a subtype of Float then how would you deal with the
> representation of floating point numbers?
Subtypes are not required to share representations of their values.
> If you use hardware-supported 32-bit representation of floats then
> there will be a problem with precision. Some Int values cannot not be
> precisely represented as floats.
That is up to inherited operations. Basically, if Integer inherits
anything from Float it also does the property of Float being an
interval of [real] numbers, with the consequences of. If Integer can
do this operation better, then it should override. The third
alternative is adding ideal values to the class in the form of NaN or
else an exception propagation.
> If you use your own representation of Floats then you will have
> inefficient floating point ops.
No, the operations defined on the common class may have distinct
implementations for different types (from the class).
Only inherited operations composed with an implicit conversion of the
representation will be slower. But that is exactly what OP wished to
do, using explicit conversions instead... My point was that explicit
conversions are usually bad. They suggest either some subtyping
relation (which has to be articulated), or else a manifestation of
some design problem.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
Return to the
comp.compilers page.
Search the
comp.compilers archives again.