develooper Front page | perl.perl6.language | Postings from April 2003

Re: HELP! Type Coercions [was Re: Do we really need the dual type system?]

Thread Previous | Thread Next
From:
John Williams
Date:
April 18, 2003 12:04
Subject:
Re: HELP! Type Coercions [was Re: Do we really need the dual type system?]
Message ID:
Pine.LNX.4.33.0304181259240.18483-100000@sharkey.morinda.com
On Fri, 18 Apr 2003, Jonathan Scott Duff wrote:

> On Fri, Apr 18, 2003 at 12:15:18PM -0600, John Williams wrote:
> > On Fri, 18 Apr 2003, Paul wrote:
> > > What's the point of
> > >   my Int $i; # ?
> >         ^  ^
> >         |  variable/container type
> >         value type
> >
> > It's a scalar variable which can only hold Int values.
>
> So ...  $i = "1231" is an error?  What about  $i ~= "5"?  (Where ~= is
> the new concat-assign as I understand things)
>
> These are things that I think shouldn't be errors unless you've asked
> for them to be so. And using typed values is necessary, but isn't
> sufficient to ask for value type-checking IMHO.

Well, the answers to that involve type conversions, and I've been staying
out of that part of the conversation.  However, I am confident that
$i = "abc" is an error.  I'm not sure about $i ~= 5, but since ~ is a
string operation, I suspicion an error there too.

> I've always thought that the "Int" in "my Int $i;" was just a compiler
> hint that says "when in doubt, treat this as an Int", but that it would
> be perfectly okay to put non-Int things in the $i container or to do
> non-Int operations upon it.

It's more of an assertion than a hint.

~ John Williams


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About