comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: user-defined type conversion
Date: Mon, 20 May 2002 06:21:24 GMT
Date: 2002-05-20T06:21:24+00:00	[thread overview]
Message-ID: <3CE895D9.5F635D2A@acm.org> (raw)
In-Reply-To: bebbba07.0205191925.548bea7a@posting.google.com

Russ wrote:
> 
> Yes, I meant "arg" rather than "feet", and I don't think it's an
> infinite resursion. The "inches" function takes a "feet" argument,
> whereas the call of "inches" within it takes a "float" argument.
> That's two different functions.

I thought you were trying to write a type conversion to complement or
replace the existing type conversion "inches". Type conversions of this
sort may have a value of any numeric type as the argument, so clearly
your user-defined equivalent must behave the same way, leading to
infinite recursion.

One cannot consider a numeric type declaration as declaring a number of
overloaded functions with the same name as the type and parameters of
every other numeric type because one can apply type conversions to
numeric types not known at the point of the declaration.

> I still don't see why I shouldn't be able to make my own type/unit
> conversion that has the same simple syntax as the built-in type
> conversions. Until I do, I consider it a minor deficiency of the
> language.

I don't see why I can't define subprograms in terms of pattern matching.
I don't see why I can't define new operators. I don't see why I can't
write natural English and have the Ada compiler generate appropriate
code. Are these deficiencies of Ada or of my understanding?

There are many features that it would be nice for Ada to have. The
ability to have user-defined type conversions with the same name as a
type is one of them. It's difficult to have a consistent language
definition that allows this and all the good things that Ada does allow,
so the language designers do not allow it.

Of course, you can define a function with the same name as the type in a
different declarative region, but you won't be able to refer to both the
type and the function in the same scope without a prefix on at least one
of them.

-- 
Jeff Carter
"If you think you got a nasty taunting this time,
you ain't heard nothing yet!"
Monty Python and the Holy Grail



  reply	other threads:[~2002-05-20  6:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-19  7:44 user-defined type conversion Russ
2002-05-19  8:54 ` martin.m.dowie
2002-05-19 10:44 ` David C. Hoos, Sr.
2002-05-19 18:29   ` Russ
2002-05-19 20:58     ` David C. Hoos, Sr.
2002-05-19 21:12     ` Jeffrey Carter
2002-05-21  9:18       ` Dmitry A. Kazakov
2002-05-19 19:01 ` sk
2002-05-20  3:33   ` Russ
2002-05-20 19:27     ` Randy Brukardt
2002-05-20 19:45       ` David C. Hoos
2002-05-19 21:17 ` Jeffrey Carter
2002-05-20  3:25   ` Russ
2002-05-20  6:21     ` Jeffrey Carter [this message]
2002-05-21  9:30       ` Dmitry A. Kazakov
     [not found]     ` <mailman.1021892102.6644.comp.lang.ada@ada.eu.org>
2002-05-20 19:26       ` Russ
2002-05-21  9:35         ` Dmitry A. Kazakov
2002-05-22  4:32         ` Russ
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox