You're right in that C# and Java have a lot of duplication in this case. It'd certainly be nice to have to type what I mean only once. Here's some food for thought, though.

A good type-inferring system can gather, at compile time, the type of $dog in this construct:

my $dog = Dog->new();

I'll probably write much, much more code that actually works with a Dog than code that instantiates a Dog. It seems more valuable to have the option to strictify your type checking these situations, where type inference really can't help:

method bark_at (Dog $some_other_dog, $message) { # horrible Perl6y pseudo-code print "$.name says to $some_other_dog.name, '$message'\n"; };

I wouldn't expect bark() to autoinstantiate a Dog object, but effectively it's declaring a lexical $some_other_dog that somehow conforms to Dog.

It'd also be weird to say:

class DogShow { my Dog @showdogs; }

and fill an array with placeholder Dogs. I might want to throw a robot dog in there, or a Puppy, or something that's not specifically a Dog.


In reply to Re: Fun with Typed Objects 1 by chromatic
in thread Fun with Typed Objects 1 by John M. Dlugosz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.