Re: Common Lisp solved this problem 20 years ago
Per Bothner 26 Oct 2005 22:13 UTC
Thomas Bushnell BSG wrote:
> Per Bothner <xxxxxx@bothner.com> writes:
>
>
>>Taylor Campbell wrote:
>>
>>>I'm a bit unclear on one part of your proposal: is the type
>>>declaration syntax merely a suggestion to the compiler, or does it
>>>actually affect the semantics of a program?
>>
>>The latter, but perhaps not quite the way you're thinking.
>>(let ((V :: TYPE init)) ...)
>>has semantics like:
>>(let ((V (coerce-to-TYPE init))) ...)
>
> I dislike this, because it's a hidden semantic in the type
> declaration.
Huh? What's hidden about it? That's the *primary* semantics
of a non-hidden syntax.
> Why not declare that (let ((V :: TYPE init)) ...) is an error if the
> init doesn't return something of the proper type?
It does that, if the value isn't convertible.
But if you go along with the basic model that modular arithmetic is
selected based on the type of the operands, then we need a way
to convert a normal integer to a modular integer, and back again.
The coercion model provides that in a convenient way.
--
--Per Bothner
xxxxxx@bothner.com http://per.bothner.com/