On Thu, Aug 11, 2005 at 10:47:35AM +0800, Autrijus Tang wrote:
: Really this is about path of least resistance.  Without inference,
: we are asking the user to choose between:
: 
:     1) Verbose annotation and type safety
:     2) Convenience (no annotation) and unsafe behaviour
: 
: Adding inference ("is typed") to the mix massively sweetens the first
: option, which would be a good thing.

Only if the programmer can be taught to understand the inferences...

: > Do you have a non-trivial application for this in mind?
: 
: Yes.  But I can only show trivial examples:
: 
:     use traits <typed>;
:     my $test = Test::Builder.new();
: 
: Now, without inferencing (the first line above), $Test would have to be
: dynamically typed (no typechecks possible), essentially forcing the user
: who wants typechecks to write out by hand:
: 
:     my Test::Builder $test = Test::Builder.new();

That's why we have:

   my Test::Builder $test .= new();

: This is silly.  Or, take another trivial (but common) example:
: 
:     method skip (--> Test::Builder::Test::Skip) {
:       my Test::Builder::Test::Skip $skip = Test::Builder::Test::Skip.new;
:       my Test::Builder::Test::Base::Status $status = $skip.status;
:       $status.do_something; $skip.do_something; # ...
:       return $skip;
:     }

    my Test::Builder::Test::Skip $skip .= new;

: With inferencing:
: 
:     use traits 'typed'; 
:     method skip (--> Test::Builder::Test::Skip) {
:       my $skip  .= new;
:       my $status = $skip.status;
:       $status.do_something; $skip.do_something; # ...
:       return $skip;
:     }
: 
: Which language do you want to write in? :-)

Probably the first, actually, given the .= shortcut.  It takes *me*
a lot of thought to reproduce in my head what the inferencer is doing
there, and you can't really understand code unless you can play the
same mindgames the computer is playing.  When the computer gets too
smart, it forces anyone of less-than-genius caliber into cargo-cult
programming.  That's what I don't like about type inferencing systems.

And there's something to be said for locating type information near
the "my" declaration for documentation purposes even if it's entirely
redundant.

: > It reminds me a bit to the 'bind a variable once in the constraint
: > store' of the constraint programming paradigma.
: 
: No, I didn't have that in mind; I think it's just local type inferences.
: 
: > But there it serves as guiding the control flow. What is the purpose
: > in a typed, imperative language as Perl6?
: 
: The purpose is that we don't have to be strong typists to enjoy Strong
: Typing.  To make Perl6 easier to type, and easier to Type.

Sure, but you're kinda smart, so you can just remember what you've
typed and/or Typed.  Stupid people also have to worry about reading
the code.  :-)

Actually, this is a case where a declared return variable would reduce
my cognitive load since I don't have to scan for a return statement
to see that $skip is in fact the return value:

    use traits 'typed'; 
    method skip (--> Test::Builder::Test::Skip $skip) {
        $skip .= new;
        my $status = $skip.status;
        $status.do_something; $skip.do_something; # ...
    }

Arguably that's just locating the type near the "my" again, though the
"my" is implicit in the signature in this case.

Larry

Reply via email to