Re: Declaring super types
Date: Mon, 19 Apr 2010 11:07:31 -0700 (PDT)
Message-ID: <04857acf-90f2-4e90-80b6-e002499c78d0_at_r28g2000vbi.googlegroups.com>
On Apr 19, 9:16 am, David BL <davi..._at_iinet.net.au> wrote:
> On Apr 19, 8:23 pm, Nilone <rea..._at_gmail.com> wrote:
>
> > How would you want to use that relationship? Any examples to study?
>
> For example, functions that accept RATIONAL values could be passed
> values of type INTEGER.
>
> It’s quite useful. E.g. even in a low level language like C there are
> handy conversions amongst the built-in types:
>
> double sqrt(double);
>
> double x = sqrt(4); // integer 4 has implicit conversion to double
>
> BTW C++ allows one to write user-defined value types supporting
> implicit conversion from builtin-types, by writing single argument
> constructors. Actually I just posted to comp.lang.c++.moderated
> asking whether it can be regarded as a general purpose approach to
> value subtyping in that language. But it does seem strange for a type
> to declare itself as a supertype of another type.
In other words, totally drop these notions of sub/super/duper
type and most if not everything is simpler and more clear. In
this specific case there would simply be a function signature
() : INTEGER -> RATIONAL
declared somewhere with some name or anonymous as above that
defines a coercion for this multi-sorted algebra. That is it.
C++ let's one think this way /most/ of the time (thanks to overloading, template, etc). Unfortunately some operators must be member functions which is an annoying asymmetry.
KHD PS. The "no names allowed" thread became a total annoying mess as soon as ill-defined nearly useless sub/super/duper language crept in. (Not to say it wasn't on the verge of mess from the very start ;-). Received on Mon Apr 19 2010 - 20:07:31 CEST