My apologies if these have been answered.  I've been chatting with
Jonathan Worthington about some of this and any misconceptions are
mine, not his.

In reading through S12, I see that .can() returns an iterator for the
methods matched.  What I'm curious about is this:

  if $obj.can('fribble') {
    my BadPoet $jibbet = $obj.fribble('repeatedly');
  }

Just because $obj.can('fribble') does not mean that the available
fribble(s) will accept a string argument or return BadPoet instances. 
In chatting with Jonathan about this, he speculated that I would have
to manually walk the method objects in the iterator to find out if I
really have a suitable method.  This seems like what we really have is
$object.might($method).  Is there a simpler way of determining if
there's an appropriate method for what I need?  It seems like what we
really want is a method object where I can declare a signature and then
do this:

  if $obj.can($object_with_signature){ ... }

This raises my second question.  What if I have this?

  class MadHatter is BadPoet { ... }

If I get back a MadHatter instead of a BadPoet, but I really want the
superclass and not a subclass, how can I enforce that?  Do I have to do
something like this?  (pseudo-code)

  subset ReallyABadPoet where { $^N.type eq "BadPoet" }
  my ReallyABadPoet = $obj.fribble('reapetedly');

That seems to fail because the you'd have to invoke every method to
guarantee that you're really getting back the exact type you want.  As
such, it seems like we'd need return values to guarantee that the
returned type is exactly what we claimed.

  method foo(Int $bar, Int $baz) returns Int {
    return $foo/$baz;
  }

Since the return value might be a Float, does it get cast to an Int,
thereby discarding information?

Cheers,
Ovid

--

Buy the book -- http://www.oreilly.com/catalog/perlhks/
Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/

Reply via email to