dHarry has asked for the wisdom of the Perl Monks concerning the following question:

Dear OO-enlighted Monks,

My interest in Perl6 is rapidly growing but sometimes I can’t appreciate/understand a specific language construct. Take for example partial types. The idea seems to stem from Type inference with partial types, Thatte 1988.

I looked around:

In C# it seems to boil down to: allow a single class to be defined in more than one file. See for example What Are Partial Types in C#? and Working with Partial Types. The wiki pages seem to be based on that approach.

In Perl6 it seems something completely different though (correct me if I am wrong).

Could some OO-enlighted/Perl6 Monk explain to me:

  1. What the partial types in Perl6 are?
  2. Why we want/need them?
  3. What the trade-off is: advantages/disadvantages of partial typing?
  4. Isn’t Multiple Inheritance (evil?!) some kind of partial typing?
  5. How does this compare to multiple-type objects?

Cheers
dHarry

Update: Added link to Multiple-type objects in an enhanced C++ persistent programming language.

Replies are listed 'Best First'.
Re: Perl6 Partial Typing
by moritz (Cardinal) on Sep 05, 2008 at 09:47 UTC
    If I understand the concept of "partial types" correctly (from the C# example), in Perl 6 this simply looks like that:
    class Foo { # code here } ... class Foo is also { # more code here }

    And they are usually called "open classes".

    Why we want/need them?

    Suppose you are not happy with the Perl 6 prelude, and want more methods in "basic" types:

    class Int is also { method frob { say "frobbed {self}"; } } 4.frob;
    Isn’t Multiple Inheritance (evil?!) some kind of partial typing?

    Multi Inheritance isn't evil (it's only evil if your tools aren't good enough). And it's different from partial types that it doesn't extend existing classes.

    How does this compare to multiple-type objects?

    What's a multiple-type object?

Re: Perl6 Partial Typing
by dragonchild (Archbishop) on Sep 06, 2008 at 02:27 UTC
    Like so many other things, Perl6 defines terms somewhat differently. A "partial type" is a type definition that cannot stand on its own. Therefore, if the other supporting pieces aren't there, it's a compile error.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?