develooper Front page | perl.perl6.language | Postings from November 2002

any type

Thread Next
From:
Tanton Gibbs
Date:
November 29, 2002 03:32
Subject:
any type
Message ID:
00a501c297ab$9d7b4ae0$ac02db40@pavilion
Has there been any discussion about having an "any" type.  Something such as:

my any $x = "Hello";
$x = 17.3;
$x = Foo.new;

I realize that this can be accomplished with an untyped variable, but there may be a reason not to do that.  Namely, there most probably will be some sort of pragma like "use strict 'type'" which will ensure every variable is typed.  Furthermore, even it typed programs it may be useful to have a datastructure that can contain different types of values (e.g., hash of any, array of any).  Therefore, it would be very convienient to have an any type.  It may be that UNIVERSAL's Perl6 counterpart plays this role, but I would think that it would only hold objects, not things like int and string (although they could be promoted ot Int and String automatically).  Secondly, if we do have an any type, there should be some way to figure out what the type really is.  Something like, but more powerful than, Perl5's ref function.  It should tell the user what the type is in an easily understandable fashion...it should also give the user as much information as possible.  For example:

my any %hash;
my any @arr;
my int @intarr;
my Foo $f;
%hash{arr} = \@arr;
%hash{intarr} = \@intarr;
%hash{Foo} = $f;

type_of( %hash{arr} ) == ("array", "any" );
type_of( %hash{intarr} ) == ("array", "int" );
type_of( %hash{intarr}[7] ) == ("int");
type_of( %hash{Foo} ) == ("Foo");

On a tangential note, how would you specify a hash of arrays of ints?

Comments?
Tanton


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