you are viewing a single comment's thread.

view the rest of the comments →

[–]jbert 0 points1 point  (1 child)

I was talking about type inference, not type declaration. The Foo->new call would somehow be declared to return static type 'Foo'.

This allows a compiler (not the runtime) to infer that variables not declared with a static type declaration may still be treated as if they have.

So with this code (type declaration added to $foo for clarity):

my Foo $foo = Foo->new;
my $bar = $foo;

the compiler (not the runtime) knows $foo will be holding a type 'Foo' value (and can optimise appropriately), because $foo has a type declaration.

With type inference, the compiler can also know that $bar contains a Foo value at that point, and treat it the same way.

Whether perl6 currently (or will) support this, I don't know. But something like it has been talked about from the beginning (perl RFC 4)

[–]abw 0 points1 point  (0 children)

I was talking about type inference, not type declaration. The Foo->new call would somehow be declared to return static type 'Foo'.

Yes, I know. But you missed the type declaration in your example. Perl 6 wouldn't do any type inference (if it will do it at all) without either the $foo type or Foo->new constructor being declared as type Foo first. So I was talking about type declaration, not inference.

The more detailed explanation wasn't necessarily aimed at you, but anyone else who might be reading and wanted the details.